Password Reset Security
What you'll learn: How to design secure password reset mechanisms that protect user accounts from takeover.
The Vulnerability of Password Resets
Password reset flows are a common attack vector. If poorly designed, they can become the weakest link in your authentication system—even if passwords are stored with Argon2 and perfect entropy! A compromised reset flow lets attackers bypass password security entirely.
Core Security Principles
Token Generation
When a user requests a password reset, generate a cryptographically secure random token (not predictable sequences or short numeric codes). This token should be:
- At least 32 bytes of randomness (256 bits)
- Generated using a cryptographic random number generator
- Unique per request
Think of it like a one-time-use key: unpredictable, single-purpose, and time-limited.
Token Storage
Store reset tokens hashed in your database, just like passwords. Use the same secure hashing algorithms you learned (bcrypt, Argon2). If your database is breached, plain-text reset tokens are as dangerous as plain-text passwords.
Expiration Windows
Tokens must expire quickly—typically 15-60 minutes. Short lifespans limit the window for attackers to exploit intercepted reset emails.
Abuse Prevention
- Rate limiting: Restrict reset requests per email/IP to prevent spam or enumeration attacks
- No information disclosure: Never reveal whether an email exists in your system ("If that email exists, we sent a reset link")
- Invalidate on use: Once a token resets a password, destroy it immediately
- Invalidate old tokens: When a new reset is requested, invalidate all previous tokens for that account
Key Takeaway: Secure password reset requires cryptographically random tokens, proper hashing, short expiration, rate limiting, and careful information disclosure to prevent account takeover attacks.