(Note · · 6 min read)

Your password reset tells attackers which emails are real

Password reset is a full authentication path that bypasses the password. It gets less attention than login, which is why it is so often the way in — and most of its weaknesses are decisions made without noticing a decision was being made.

By Md. Habibur Rahman Shohel, full-stack & AI product engineer in Dhaka

Answer the same way every time

If an unknown address produces a different message, a different status or a visibly different response time from a known one, the form has become a tool for discovering which addresses hold accounts. That list is the first step of a credential-stuffing attempt.

Return the same confirmation regardless, and do the work after responding so timing does not distinguish them. The same applies to registration, where a duplicate-address error leaks the same information.

The token is a credential

Generate it from a cryptographically secure source with enough length to be unguessable, and store only its hash. A reset table holding usable tokens in plain text is a table that hands out accounts if it is ever read.

  • Short expiry — long enough to find the mail, not long enough to sit in an inbox for a week.
  • Single use: invalidate on use, and invalidate outstanding tokens when a new one is requested.
  • Bound to one account, and never derived from the user's identifier, email or a timestamp.
  • Compared in constant time, and looked up by hash rather than fetched and compared in the application.

Keep it out of places that log URLs

A token in a query string ends up in server logs, analytics and the referrer sent to any third-party resource the page loads. Prefer a path segment or a form post, and make sure the reset page loads nothing external.

Never put the new password in a link, and never email a password. The link proves control of the mailbox; the password itself is chosen afterwards, over an encrypted connection.

Rate limit by account and by source

Unlimited requests let someone flood a user's inbox, and unlimited attempts at submitting a token let it be guessed. Limit both, and limit per account as well as per address — one of those alone is straightforward to work around.

Keep the limit's response identical to the ordinary one for the requester, so the limit itself does not become the signal that an account exists.

Finish the job after the reset

Changing the password is not the end of it. Invalidate existing sessions, so an attacker already signed in is removed. Invalidate other outstanding reset tokens. Then send a confirmation to the address, naming the time and offering a route to report it.

That confirmation is how a genuine owner discovers an unauthorised reset at all. It is also why an email change should require confirmation at the old address — otherwise an attacker changes the address first and the warning goes to them.

First login is a reset too

An account created by an administrator has the same problem: a credential that travelled to the user somehow. Treat it as single-use and require a change at first login — which is how the mailboxes on the mail platform I run were rolled out, each credential sent as an individual message rather than in a list, with a forced change on first sign-in.

One detail from that rollout generalises: where a recipient's address looked like a near-miss of a well-known provider's domain, it was held back and queried rather than guessed at. A credential sent to a wrong address is the same event as a leaked one, and no reset flow can undo it afterwards.

Common questions

Should a password reset form say whether the email exists?

No. A different message, status or response time turns the form into a tool for discovering which addresses hold accounts. Return the same confirmation every time and do the work after responding so timing does not distinguish them.

How should reset tokens be stored?

Generate from a cryptographically secure source with enough length to be unguessable, and store only the hash, looked up by hash rather than fetched and compared. A table holding usable tokens in plain text hands out accounts if it is ever read.

What should happen after the password changes?

Invalidate existing sessions so an attacker already signed in is removed, invalidate other outstanding tokens, and email a confirmation naming the time with a way to report it — that message is how a genuine owner learns of an unauthorised reset.

Do administrator-created accounts need the same care?

Yes. The initial credential travelled to the user somehow, so treat it as single use and force a change at first login. Send credentials individually rather than in a list, and query an address that looks like a near-miss of a known domain rather than guessing.

Need something like this built?