Authentication

Build Secure Password Change and Account Recovery Flows

Protect sensitive account changes with reauthentication, single-use tokens, notification and session invalidation.

Password changes and account recovery are high-value workflows because they can transfer control of an account. They need stronger safeguards than ordinary profile edits and should be designed as explicit state transitions.

Require appropriate proof

For an authenticated password change, request the current password or another suitable reauthentication factor. For recovery, use a high-entropy, single-use token delivered through a verified channel. Do not use predictable values or expose tokens in analytics and application logs.

Store tokens safely

Store a hash of the recovery token rather than the raw token. Set a short expiration, bind it to the intended account and invalidate it after use. Make token consumption atomic so concurrent requests cannot reuse the same token.

Notify and invalidate sessions

Notify the account owner after a successful credential change. Consider invalidating other active sessions and recovery tokens so an attacker cannot continue using an old session or link. Provide a secure process for users who lose access to their verified channel.

Avoid account enumeration

Recovery responses should not reveal whether an email address is registered. Use consistent response text and avoid large timing differences between existing and unknown accounts.

Checklist

  • Reauthenticate before sensitive password changes.
  • Use random, single-use, expiring recovery tokens.
  • Store only token hashes.
  • Notify users and review active sessions.
  • Keep account-existence responses consistent.
Share this page Help other developers discover this resource.