Password Reset Flows and Security Tokens
What you'll learn: How to implement secure password reset mechanisms that don't accidentally create vulnerabilities while helping legitimate users regain access to their accounts.
The Core Problem
Password resets are a critical but dangerous feature. Users forget passwords constantly, so you must provide a way to reset them—but a poorly designed reset flow essentially hands attackers a backdoor to any account. The challenge is proving someone's identity without already having their password.
Security Token Approach
The industry-standard solution uses time-limited, single-use tokens:
- User requests a password reset via email
- System generates a cryptographically random token (not predictable like sequential numbers)
- Token is stored alongside the user record with a short expiration timestamp (typically 15-60 minutes)
- Token is sent via a secure channel (email link, SMS)
- User clicks link, system validates token hasn't expired or been used
- After successful password change, token is immediately invalidated
Common Pitfalls to Avoid
Never reveal whether an account exists. Always show "If that email exists, you'll receive a reset link" rather than "No account found"—otherwise attackers can enumerate valid users.
Make tokens unpredictable. A token based on userId + timestamp can be guessed. Use cryptographically secure random generators (128+ bits of entropy).
Limit token lifetime aggressively. One hour maximum. This bounds the window of vulnerability if an email account is compromised.
Invalidate old tokens immediately when a new reset is requested or password changes successfully.
Don't send the new password via email. Always require the user to choose a new password after clicking the token link.
The Analogy
Think of it like a hotel giving you a temporary keycard that only works for your specific room, expires in one hour, and becomes useless once you've checked in and gotten your permanent key.
Key Takeaway: Secure password reset requires time-limited, unpredictable, single-use tokens sent through verified channels, with careful attention to preventing account enumeration and token prediction attacks.