Security Basics

8 min

How to Prevent Login Brute Force Attacks

How to Prevent Login Brute Force Attacks

Rate limiting alone won't stop credential stuffing. The layered defense that actually works: progressive delays, MFA on privileged accounts, hardened password reset, and the session controls most AI-built auth skips.

Rate limiting alone won't stop credential stuffing. The layered defense that actually works: progressive delays, MFA on privileged accounts, hardened password reset, and the session controls most AI-built auth skips.

A login endpoint can look harmless in a launch checklist: email, password, submit. But it is one of the few routes an attacker can call thousands of times without needing an account first. If you are building quickly with AI-assisted code, hosted auth and a JavaScript frontend, knowing how to prevent login brute force attacks is not optional housekeeping. It is protection against account takeover, support overhead, fraud and a breach that starts with one reused password.

Brute-force protection is not a single setting. It is a set of controls that makes automated guessing slow, expensive and visible, while keeping legitimate customers able to sign in. The right balance depends on your user base, authentication provider and risk level, but the underlying approach is consistent.

What a login brute-force attack actually looks like

The classic version is repeated password guessing against one account. In practice, startups more often face credential stuffing: attackers test username and password pairs leaked from another service. Because many people reuse passwords, a correct login may arrive on the first attempt. Rate limiting alone cannot stop that.

Attackers also spread attempts across IP addresses, use residential proxies and rotate browser fingerprints. A rule such as “block an IP after ten failures” still has value, but it should not be your only defence. If a marketplace seller, administrator or high-value customer account is compromised, the attacker may access personal data, change payout details, create fraudulent orders or invite another user into the workspace.

Your login telemetry should distinguish failed sign-ins, successful sign-ins after repeated failures, password reset requests and MFA challenges. Without that baseline, an attack can blend into normal traffic until customers report suspicious activity.

How to prevent login brute force without locking out users

Start with your authentication provider. Whether you use Supabase Auth, Clerk, Auth0, Firebase or a custom identity service, inspect the actual settings and endpoints rather than assuming the default configuration fits your application. Confirm which limits apply to password sign-in, magic links, OTP verification, account creation and password resets. These flows are all targets for automation.

Rate-limit more than the IP address

Apply rate limits at the edge or API gateway and within the authentication layer where possible. A useful design combines limits by IP address, account identifier and, where available, device or session signals. For example, permit a small number of failed password attempts for an email address within a rolling window, then impose a temporary delay before the next attempt.

Avoid permanent automatic lockouts after a handful of failures. They are easy to weaponise: an attacker can repeatedly enter a victim's email address and deny that person access. Progressive delays are usually safer. A first failure gets an ordinary response; repeated failures slow down; sustained suspicious traffic receives a longer cooldown or an additional challenge.

The response must be generic. Do not reveal whether an email exists, whether a password was nearly correct or whether an account has been locked. “Invalid email or password” is less convenient for support, but it prevents user enumeration. Use the same principle on registration and password reset pages.

Add MFA where compromise would hurt

Multi-factor authentication stops many credential-stuffing attacks because a stolen password is no longer sufficient. For admin accounts, finance users, workspace owners and anyone able to export data or modify billing, require MFA rather than making it optional.

Authenticator-app codes and passkeys are generally stronger choices than SMS. SMS may be appropriate when it is the only realistic onboarding option, but it carries SIM-swap and delivery risks. Passkeys are especially useful for a modern SaaS product because they reduce phishing exposure and remove the need for users to manage another password. They do, however, require careful account-recovery design.

Do not treat MFA as a checkbox feature. Verify that sensitive actions prompt for recent authentication, especially changes to email address, password, payout destination, API keys and recovery methods. A session stolen from an unattended device should not be enough to redirect money or take ownership of an account.

Make password recovery harder to abuse

Password reset is often the weaker route around a well-defended login form. Rate-limit reset requests, use short-lived single-use tokens and invalidate outstanding reset tokens when the password changes. Do not put reset tokens in application logs, analytics events or client-side error reporting.

Send an alert when a password changes and provide a clear way to report an unauthorised change. If users can change their email address, require confirmation through the existing email address or a recent MFA check. Otherwise, an attacker with a live session can quietly make recovery point to their own inbox.

Check the implementation, not just the sign-in screen

AI-generated authentication code can appear credible while making unsafe assumptions about JWTs, redirects or server-side access. The login form is only one piece of the attack surface.

Check that the backend validates tokens using the expected issuer, audience, expiry and signature algorithm. Never accept unsigned JWTs or let the client decide a user's role. Keep service-role keys out of frontend bundles, environment files committed to Git and browser-accessible API routes. An exposed Supabase service-role key can bypass row-level security entirely, making a carefully protected login flow irrelevant.

Review redirect handling after authentication and password reset. A next or redirectTo parameter should accept only approved internal paths. Open redirects can help phishing campaigns imitate your sign-in process and capture passwords or MFA codes.

Also check session behaviour. Set cookies with HttpOnly, Secure and an appropriate SameSite value when using cookie-based sessions. Rotate session identifiers after login and privilege changes. Set sensible session expiry, then require reauthentication for high-risk actions. Very short sessions can frustrate normal users; very long sessions increase the impact of a stolen device or token. Choose according to the data and capabilities in the account.

Monitor for patterns that need a response

A login defence that does not produce useful alerts becomes a silent failure. Record security events without storing passwords, reset tokens or full authentication secrets. At minimum, capture timestamp, account identifier where applicable, result, source IP, user agent, MFA outcome and the reason for a blocked request.

Set alerts for a spike in failed logins, large numbers of accounts tried from one source, a single account targeted from many sources, unusual reset activity and successful logins following a run of failures. For privileged accounts, notify the user of new-device sign-ins or unusual locations, while recognising that geolocation is an imperfect signal for mobile networks and VPNs.

Have an operational response ready before an incident. Someone should know how to revoke sessions, force a password reset, suspend a high-risk account, preserve relevant logs and contact affected customers. This matters for a two-person team as much as a larger company. The person handling support on a Saturday should not have to invent the process during an account takeover.

A practical hardening sequence for a live SaaS app

If your app is already live, do not wait for a full rebuild. Work through the highest-impact controls first:

  • Confirm provider limits for sign-in, registration, OTP and password reset routes.

  • Add layered rate limits and progressive delays, with generic authentication errors.

  • Require MFA for administrators and accounts that control money, users or sensitive data.

  • Review token validation, session cookies, redirects and exposed credentials in the repository.

  • Add alerting and document who can revoke sessions or disable access during an incident.

Then test the controls. Use a staging environment where possible, but test the deployed configuration too. A rate limit defined in application code may be bypassed if an alternate API route, serverless function or identity-provider endpoint remains exposed. Confirm that a blocked request is logged, that an alert reaches the right person and that a genuine customer can recover access without unnecessary friction.

For fast-moving products, an independent review is useful because authentication failures rarely sit in one file. HollowByte audits the live application and repository together, checking login controls alongside JWT handling, RLS, API exposure and account-level authorisation. The goal is to identify the exact route, configuration or code path that turns a routine sign-in feature into a takeover risk.

Your customers should be able to sign in quickly. Attackers should find every repeated attempt slower, less informative and easier for your team to spot.

Back to blog