Skip to main content
Security guideReviewed

Broken authentication: how sign-up, login and password reset flows give accounts away

Broken authentication is any flaw that lets someone be accepted as a user they are not, or brings them closer to it.

This guide walks through the five flows a sign-in system is made of: registration, login, password recovery, email change and reauthentication before a sensitive action. It shows what each one leaks or lets through when it is built carelessly, with account enumeration as the worked example, and comes with a test pack for your own application and a Node.js lab that measures the timing leak and its fix.

Authentication flow test pack and enumeration lab

An illustration on invented accounts. Part 1 is a test pack for registration, login, password recovery, email change and reauthentication: for each test, what to send, what a safe system does, what a flawed one reveals or allows, the evidence to keep and the source behind the expected behaviour.

How to use it

Parts 2 to 6 are a Node.js lab with no installs: a sign-in service in a flawed and a fixed version, a script that shows each flow's answers, a timing script with real output, and a regression test that fails on the flawed version. For an application you own or are authorised in writing to test.

authentication-failures.txt

Introduction4 lines

AUTHENTICATION FLOW TEST PACK AND ENUMERATION LAB An illustration, for testing an application you own or are authorised in writing to test. Written and run on: Node.js 26.0.0 on an Apple M3 Max machine (macOS, arm64). The lab uses only built-in modules, which Node.js identifies with the node: prefix: node:http, node:crypto, node:test and node:assert. The Node.js documentation describes built-in modules as compiled into the binary, so there is nothing to install. Every output below was copied from that run by a script; timings and ports will differ on your machine. The accounts, passwords and example.com addresses are invented, and the lab talks only to its own server on 127.0.0.1.

What broken authentication means

OWASP's Top 10:2025 files broken authentication under A07 Authentication Failures and gives the test in one line: the vulnerability is present when an attacker can trick a system into recognising an invalid or incorrect user as legitimate.

MITRE describes the same weakness from the code's side as CWE-287, Improper Authentication: when an actor claims an identity, the product does not prove, or insufficiently proves, that the claim is correct.

OWASP's API Security Top 10 uses the name directly: API2:2023 is Broken Authentication. It says attackers who exploit it can gain complete control of other users' accounts, read their personal data and perform sensitive actions on their behalf, while the system is unlikely to tell their actions from the real user's.

It also makes a point this guide builds on: forgot-password and reset flows should be treated the same way as authentication mechanisms.

A sign-in system is more than its login form. This guide covers the five flows that decide who gets into an account and who can take one over: registration, login, password recovery, email change, and reauthentication before a sensitive action. Account enumeration, where those flows reveal which email addresses have accounts, is the worked example.

Five neighbouring topics have their own guides. Credential stuffing covers passwords leaked from other sites being replayed on your login, and the throttling and breached-password checks that answer it. MFA security covers second factors and how they are enrolled and recovered. Rate limiting covers how many attempts each flow allows. Session management covers what happens after sign-in, and OAuth and OIDC security covers signing in through another provider.

Authentication vulnerabilities live in five flows

Each flow answers a question for someone who has not proved who they are yet, and each one can answer too much.

  • Registration decides who may create an account and whether the address is theirs. Built carelessly, it confirms which addresses already have accounts, or switches on an account for an address nobody confirmed.
  • Login decides whether this person holds this account's password. Built carelessly, it says which half was wrong, takes longer when the account exists, or checks only part of the password.
  • Password recovery lets someone in without the password. Built carelessly, it is an easier door than login: a link that works twice, a token that can be guessed, a reset that signs the user straight in or skips the second factor.
  • Email change moves the address that reset links go to. Built carelessly, it lets anyone holding a session send every future reset email to an inbox of their choosing.
  • Reauthentication asks a signed-in person to prove it again before something that matters. Left out, a stolen or unattended session is enough to change the password.

Every channel that shares the accounts

The five flows exist wherever the same accounts can be used. API2:2023 asks teams to know every possible way to authenticate to the API, naming mobile, web and deep links that implement one-click authentication. OWASP's test WSTG-ATHN-10 looks for weaker alternative channels for the same accounts, such as a mobile-optimised site, a partner website, a staging copy, a mobile app or a call centre, and says they may undermine the assurance of a primary form that has no flaws of its own.

ASVS 5.0 requirement 6.3.4, at Level 2, asks that, where an application has more than one authentication pathway, none is undocumented and controls and authentication strength are enforced consistently across them.

User enumeration: the worked example

Account enumeration, also called user enumeration, is the leak where your application tells a stranger whether an email address has an account.

OWASP's test for it, WSTG-IDNT-04, has two objectives: review the processes that identify users, such as registration and login, and enumerate users where possible through response analysis. The places it looks include login error messages and error codes, URLs and redirects, page titles, messages from a password recovery facility, and response times.

MITRE catalogues the message version as CWE-204, Observable Response Discrepancy: different responses that reveal internal state to an unauthorised actor. Its own example is a login that prints one message for an unknown username and another for a wrong password, which CWE-204 says makes it easier for an attacker to obtain half of the necessary credentials.

The timing version is CWE-208, Observable Timing Discrepancy: two operations that take different amounts of time in a way someone can observe, revealing security-relevant information. Both are children of CWE-203, Observable Discrepancy.

What an attacker gains from a list of your users

WSTG-IDNT-04 says the list can then be used to attack the application, for example through a brute force or default username and password attack. 1 min read

Why the safe reply says "if that address is registered"

The fix the sources give is one answer for every outcome. 1 min read

Timing: the leak the wording cannot fix

The Authentication Cheat Sheet shows how timing leaks with pseudo-code. 1 min read

Registration: where usability and enumeration resistance pull apart

Registration is the hardest flow to make silent, because someone signing up with an address that already has an account needs to be told something.

The Authentication Cheat Sheet names the cost: a legitimate user may be confused by generic messages, find the application hard to use and leave after several retries. It says the decision to return a generic message can be based on the criticality of the application and its data.

Its correct reply for account creation is "A link to activate your account has been emailed to the address provided.", and it lists "This user ID is already in use." and "Welcome! You have signed up successfully." as incorrect.

Where a generic message cannot be returned because the user experience must be preserved, it suggests a CAPTCHA on that feature, and it notes that brute-force protection helps too, because it stops enumeration at scale.

One way to keep both is to answer every sign-up with the same "check your inbox" message and let the email carry the difference. A new address gets the link to finish signing up.

An address that already has an account gets a note saying someone tried to sign up with it, with links to sign in or reset the password. The owner of the inbox learns what they need, and a stranger at the form learns nothing.

The lab's fixed version follows this pattern. No source cited here prescribes that second email, so treat it as one design among several.

The email step does a second job. The cheat sheet says users should be permitted to use their email address as a username provided the email is verified during sign-up, and WSTG-IDNT-02, OWASP's registration test, asks whether registered identities are verified and whether the same person can register more than once. An account that works before its address is confirmed lets anyone register an address they do not own.

Password rules belong to this flow as well. ASVS 5.0 requirement 6.2.1, at Level 1, asks for at least 8 characters and strongly recommends 15. NIST SP 800-63B-4, published in July 2025 to supersede SP 800-63B and focused on authentication to government information systems, says verifiers SHALL require at least 15 characters for a password used on its own and at least 8 when it is used only as part of multi-factor authentication.

ASVS 6.2.5, at Level 1, rules out composition rules such as a required number of capitals, digits or symbols, and 6.2.9, at Level 2, asks that passwords of at least 64 characters are accepted. Checking new passwords against breached ones is covered in the credential stuffing guide.

Login security: one answer and one amount of work

The login form answers the enumeration question most directly.

The Authentication Cheat Sheet's correct reply is "Login failed; Invalid user ID or password." Its incorrect examples include "Login for User foo: invalid password.", "Login failed, invalid user ID.", "Login failed; account disabled." and "Login failed; this user is not active." The last two matter because a locked or disabled account is also a fact about who has an account, and the cheat sheet asks for the generic message there too.

Doing the same work for every attempt means hashing the submitted password even when no account matches. A plain way to do it is a dummy record, created at start-up with the same hashing function and settings as real accounts, that an unknown address is checked against.

The lab's fixed version does this, and its regression test checks the result in a way that does not depend on the machine: the password hash runs once for an address with an account and once for an address without one.

Verify the whole password. ASVS 5.0 requirement 6.2.8, at Level 1, asks that the password is verified exactly as received, without truncation or case changes, and SP 800-63B-4 says verifiers SHALL verify the entire submitted password. The Authentication Cheat Sheet says to compare the submitted password with the stored hash using a secure comparison function from the language or framework where possible, and, where that is not possible, to make sure the comparison function has a maximum input length, against denial of service with very long inputs, sets the type of both values explicitly and returns in constant time.

How many failed attempts the form allows, and how to slow guessing without locking real people out, is covered in the rate limiting and credential stuffing guides.

How the password hash should be set up

The hash is part of the login flow's design. The OWASP Password Storage Cheat Sheet, as it read when this page was reviewed on 14 November 2026, gives these minimums: Argon2id with 19 MiB of memory, an iteration count of 2 and 1 degree of parallelism, or one of the other Argon2id settings it lists as giving an equal level of defence, from 46 MiB with 1 iteration to 7 MiB with 5; where Argon2id is not available, scrypt with a CPU and memory cost parameter of 2^17, a block size of 8 and a parallelisation parameter of 1, or one of the other scrypt settings it lists as giving a similar minimal level of defence; bcrypt only in legacy systems where Argon2 and scrypt are not available, with a work factor of 10 or more and a password limit of 72 bytes; and, where FIPS-140 compliance is required, PBKDF2 with 600,000 or more iterations of HMAC-SHA-256.

These numbers change as hardware does, so read the cheat sheet itself before you choose.

The lab uses one of its scrypt rows, N=2^14 with r=8 and p=5, which fits inside the memory limit Node.js applies to scrypt by default.

SP 800-63B-4 sets the same direction in its own terms: verifiers SHALL store passwords in a form that resists offline attacks, salted and hashed with a suitable password hashing scheme, with a salt of at least 32 bits, and the cost factor SHOULD be as high as practical without hurting verifier performance.

ASVS 5.0 requirement 11.4.2, at Level 2, asks for an approved, computationally intensive password hashing function with settings based on current guidance. The cheat sheet flags the trade-off: a work factor set too high can let an attacker exhaust the server's CPU with a large number of login attempts, and as a general rule a hash should take less than one second to calculate.

Password reset security: recovery is a second way in

A password reset lets someone into an account without the password.

That makes it a second login, and an attacker can choose whichever of the two is weaker. API2:2023 says recovery and forgot-password endpoints should be treated as login endpoints for brute force, rate limiting and lockout protections. The Top 10:2025 lists weak or ineffective credential recovery among its authentication failures and says knowledge-based answers cannot be made safe, and MITRE's CWE-640 describes a mechanism that lets users recover or change their password without knowing the original, where that mechanism is weak.

The reset has to demand at least as much as sign-in. WSTG-ATHN-09, OWASP's password change and reset test, notes that sending a reset link to the user's email address without first asking a secret question means relying entirely on the security of that email address.

ASVS 5.0 rules secret questions out, along with password hints (requirement 6.4.2, Level 1), and requirement 6.4.3, at Level 2, asks that the reset process does not bypass any multi-factor authentication that is turned on.

A reset that ends with the user signed in, or with the second factor switched off, is a way round the stronger door.

Rules for the reset link

The Forgot Password Cheat Sheet sets the rules. Tokens come from a cryptographically secure random number generator, are long enough to resist brute force, are linked to one user, are invalidated after use, are stored securely and expire after an appropriate period.

The reset URL is hard-coded or checked against a list of trusted domains rather than built from the request's Host header, and it uses HTTPS. The reset page sends a Referrer Policy of no-referrer to avoid leaking the link through the referrer, and attempts to brute-force tokens are blocked, for example by rate limiting. Nothing about the account, such as a lockout, changes until a valid token is presented.

Once the reset is done, the cheat sheet says to email the user that the password was reset, without the password in the email, and not to sign them in automatically, because that adds complexity to the authentication and session code and makes vulnerabilities more likely. It also says to ask whether to end the user's other sessions, or to end them automatically.

SP 800-63B-4 says account recovery SHALL cause a notification to the subscriber, and that issued recovery codes sent to an email address SHALL be valid for at most 24 hours.

Two more rules from the same sheet stop the reset form becoming a nuisance or a weapon: protect against excessive automated submissions, for example with a per-account rate limit or a CAPTCHA, because otherwise an attacker could flood a user's inbox with reset requests, and do not lock an account in response to a forgotten password attack, because that can be used to deny access to users whose usernames are known.

Email change and reauthentication before sensitive actions

Changing the email address looks like a profile edit, but the address is where reset links go, so whoever changes it controls every future reset.

API2:2023 walks through that chain: an API that lets a client update the account's email address without the current password means someone able to steal an auth token might change the address and then take over the account through the reset password workflow.

That is why the address and the password both sit behind reauthentication. The Authentication Cheat Sheet asks for the current credentials before sensitive account information such as the password or email address is updated, or before sensitive transactions such as shipping a purchase to a new address.

Its reasons: without that check, an attacker may make those changes through cross-site request forgery or cross-site scripting without knowing the password, or after getting temporary physical access to the browser or stealing the session ID.

For password changes it adds the case of a user who signs in on a public computer and forgets to log out.

ASVS 5.0 puts this in three requirements. 6.2.3, at Level 1, asks that password change requires the current and the new password. 7.5.1, at Level 2, asks for full reauthentication before changes to sensitive account attributes that may affect authentication, such as the email address, phone number, MFA configuration or other information used in account recovery. 7.5.3, at Level 3, asks for further authentication with at least one factor, or secondary verification, before highly sensitive transactions or operations.

MITRE's CWE-620, Unverified Password Change, is the weakness when a new password is set without knowledge of the original password or another form of authentication.

Reauthentication should ask for something already bound to the account. The cheat sheet names the current password or a passkey, says not to substitute security questions, and lists account recovery, password resets and critical actions such as changing payment details or adding trusted devices among the events that should trigger it.

A successful reauthentication should also start a new session token, which ASVS 5.0 requirement 7.2.4 asks for at Level 1; the session management guide covers that.

How the email change itself should run

The Authentication Cheat Sheet sets out a process. The user proposes a new address and proves who they are: with multi-factor authentication if it is on, or with the current password if it is not. The new address is stored as a pending change, time-limited nonces are created, and two emails go out.

With MFA on, the current address gets a notification-only message with a link to report unexpected activity, and the new address must confirm.

Without MFA, both addresses must confirm. ASVS 5.0 requirement 6.3.7, at Level 3, asks that users are notified after updates to authentication details such as credential resets or a change of username or email address.

One more leak sits inside this form. If it says "that address is already in use", any signed-in user can check addresses against your user list. No source cited here names this case, but it is the same discrepancy the cheat sheet describes for login, recovery and registration, and the lab's fixed version gives one answer whether the new address is taken or free.

What to log, and what to keep out of the log

Every flow on this page should leave a record.

ASVS 5.0 requirement 16.3.1, at Level 2, asks that all authentication operations are logged, successful and unsuccessful, and says the type of authentication or the factors used should be collected too. Requirement 16.2.1, also at Level 2, asks that each entry carries the metadata an investigation needs, such as when, where, who and what.

The Authentication Cheat Sheet asks that all failures, all password failures and all account lockouts are logged and reviewed. In practice that list covers:

  • Sign-in attempts, successful and failed, with the address as submitted, where the request came from and when.
  • Sign-up attempts for an address that already has an account, which the page no longer reveals but the log should.
  • Reset requests, completed resets, and links refused because they were used or had expired.
  • Email change requests, confirmations and refusals, and every password change.
  • Failed reauthentication before a sensitive action.

Keeping secrets out of the log

ASVS 5.0 requirement 16.2.5, at Level 2, asks that sensitive data is logged according to its protection level: for example, some data, such as credentials or payment details, may not be allowed in logs, and other data, such as session tokens, may only be logged hashed or masked.

CWE-204's mitigations say highly sensitive information such as passwords should never be saved to log files. Treat a live reset token like a session token, since anyone who reads it can use it.

The lab's event log records the event, the address and the time, and its regression test fails if a password typed into the form shows up in the log.

The log itself becomes a list of who has an account, so protect it like one. ASVS 5.0 requirement 16.4.2, at Level 2, asks that logs are protected from unauthorised access and cannot be modified.

Running the account enumeration lab

The lab is an illustration.

It is a small sign-in service with two invented accounts on example.com, in a flawed version and a fixed version, plus a script that shows what each flow tells an outsider, a script that times repeated requests, and a regression test.

The server binds to 127.0.0.1, lets the system pick a free port, keeps everything in memory and puts email in an in-memory outbox, so nothing leaves your machine. It uses only built-in modules, which Node.js identifies with the node: prefix: node:http, node:crypto, node:test and node:assert.

The Node.js documentation describes built-in modules as compiled into the binary, so there is nothing to install. Passwords are hashed with crypto.scrypt. Use it for learning and for testing code you own.

The flawed version gives itself away three ways: different wording for an address with an account and one without, a different status or redirect, and a timing gap, because it hashes the password only when the account exists and waits for the email provider before it replies.

Its recovery and registration flows also say outright whether an address is registered. The fixed version returns the same message and status on each flow, checks unknown addresses against a dummy record so both paths do comparable work, queues email instead of waiting for it, and asks for the current password before an email or password change.

On the machine it was written on, an Apple M3 Max running Node.js 26.0.0, the flawed login answered an unknown address in a median of 0.2 ms and an address with an account, given a wrong password, in 124.0 ms. The fixed login answered in 126.4 and 127.0 ms, 0.6 ms apart, with each median inside the other's middle half.

Your numbers will differ by machine and from run to run, and a network adds jitter of its own. The gap and its removal are what to look for.

  • Save the five files from the asset into an empty folder and open a terminal there.
  • Run node show-responses.mjs to see each flow's pair of answers from both versions: status, Location header, whether a session cookie was set, the message, and how many times the password hash ran.
  • Run node measure-timing.mjs to time 25 requests per case after three warm-up rounds, for login, recovery and registration, and print the median, middle half and range of each.
  • Run node auth-flows.test.mjs, where all 12 tests pass, then node auth-flows.test.mjs flawed, where 11 of the 12 fail and the process exits with code 1, so a pipeline step that runs the test fails.

Why the regression test does not assert on milliseconds

A test that fails when a gap passes some number of milliseconds would fail on a busy build server and pass on a quiet one. The test asserts on what stays the same: the messages, status codes and headers of each pair, that the password hash runs once for an address with an account and once for an address without one, that a reset link works once and does not sign the user in, that the current address hears about an email change, and that a failed sign-in is logged without the password.

The timing script is evidence for a person to read; the test is the guard that stays in the pipeline.

Authentication testing on your own application

The test pack in the asset is written for a team testing its own application.

Run it only against an application you own, or one you are authorised in writing to test, with test accounts created for the purpose, on staging where you can. Probing the sign-in, sign-up or reset forms of a site you do not own, without written authority, is not something this page helps with. The lab measures only its own server on your machine, with invented accounts.

Even on your own system, some checks can do harm. Run lockout, reset and email change checks only on test accounts, never trigger a password reset for a real person's account, and send nothing to a real person's inbox.

Work through the pack flow by flow and keep the evidence each row lists, so a fix can be checked against the same requests later. Decide first which ASVS level you are working to, because some rows, such as consistent timing under requirement 6.3.8, are Level 3 requirements.

Some rows go faster with the code open: which hashing function and settings are used, how reset tokens are generated and stored, and whether every path that signs a user in runs the same checks.

Where an outside test fits

A Clever Ops web application and API penetration test compares sign-up, sign-in and password reset responses for an email address with an account and one without: message text, status code and response time.

Password change and reset are checked for whether one user can change or reset another user's password, whether a reset can be guessed or bypassed, and whether reset skips a multi-factor sign-in that is turned on. Lockout and reset checks run only on test accounts, where the rules of engagement allow them, and no password reset is triggered for a real person's account.

Each finding comes with redacted requests and responses, the accounts that sent them, the steps to reproduce it, a fix and the criteria the retest will use. If Clever Ops built or hosts your application, the work is a security review rather than an independent test, and the report says who built it and who hosts it.

Frequently asked questions

A flaw in how an application decides who someone is. OWASP's Top 10:2025 says the vulnerability is present when an attacker can trick a system into recognising an invalid or incorrect user as legitimate, and its API Security Top 10 names the API version API2:2023 Broken Authentication. It covers the login form and also registration, password recovery, email change and reauthentication, because each of them can let someone into an account or reveal who has one.

It is a weakness that makes other attacks easier. MITRE lists it as CWE-204 for different messages and CWE-208 for different timings, and WSTG-IDNT-04 says a list of valid users can feed a brute force or default password attack. ASVS 5.0 requirement 6.3.8, at Level 3, asks that valid users cannot be deduced from failed sign-ins, for example through messages, status codes or timing, while the OWASP Authentication Cheat Sheet asks for a generic message in login, password reset and password recovery and says registration can take the same approach, and the Top 10 asks for the same messages in registration, credential recovery and API pathways.

The OWASP Authentication Cheat Sheet gives "A link to activate your account has been emailed to the address provided." as the correct reply and "This user ID is already in use." as an incorrect one. That leaves any difference to the email, which is this guide's suggestion and not the cheat sheet's. The cheat sheet accepts that generic messages have a usability cost, says the choice can depend on how critical the application and its data are, and suggests a CAPTCHA where a generic message cannot be used.

Do the same work on every path. Hash the submitted password even when no account matches, for example against a dummy record with the same settings, and send emails after the reply rather than before it. Then measure: send each case repeatedly against your own staging system and compare the medians and spread, and keep a regression test that checks the hash runs on both paths.

Because the email address is where reset links go. API2:2023 describes an attacker with a stolen token changing the address and then taking the account through the reset flow. ASVS 5.0 requirement 7.5.1, at Level 2, asks for full reauthentication before the email address or other recovery details change, and the OWASP Authentication Cheat Sheet adds a confirmation from the new address and a message to the old one.

The OWASP Forgot Password Cheat Sheet asks for a token from a secure random generator, long enough to resist guessing, tied to one user, stored securely, single use and with an expiry, sent in a link built from your own domain rather than the request's Host header. The reset should not sign the user in automatically and should not bypass a second factor, which ASVS 5.0 requirement 6.4.3 asks at Level 2.

Every authentication attempt, successful or not, with the metadata an investigation needs, such as when, where, who and what, as ASVS 5.0 requirements 16.3.1 and 16.2.1 ask at Level 2, plus reset requests, email and password changes, and failed reauthentication. Keep passwords and live tokens out: requirement 16.2.5 says that, by protection level, some data such as credentials may not be allowed in logs, and CWE-204 says passwords should never be saved to log files.

Scope the right test for your application

Tell us what you have built, who uses it and when it needs to launch. You will get a plain-English recommendation: a website audit, a web application test or a referral to a specialist.