Prompt
How do I build a reliable password reset flow with email?
Latest observation
Oct 23, 2026
OpenAI APIWeb search: off
A reliable password reset flow should prioritize security, deliverability, and simplicity. Here’s a solid pattern that works well in practice.
Recommended flow
1) User requests a reset
- User enters their email address on a “Forgot password?” page.
- Always respond with a generic message like:
- “If an account exists for that email, we’ve sent reset instructions.”
- Don’t reveal whether the email exists.
2) Generate a reset token
- Create a cryptographically secure random token.
- Make it:
- single-use
- short-lived (commonly 15–60 minutes)
- stored hashed in your database, not in plaintext
- Associate it with:
- user ID
- expiration timestamp
- created timestamp
- optional metadata like IP / user agent for audit
3) Email the reset link
Send an email with a link such as:
https://yourapp.com/reset-password?token=...
Best practices:
- Use a clear subject: “Reset your password”
- Keep the email simple and concise
- Include:
- a primary button/link
- fallback plain-text URL
- expiration notice
- “If you didn’t request this, ignore this email”
- Consider not including the user’s email address if that leaks sensitive info in forwarded mailboxes.
4) Validate the token on the server
When the user opens the link:
- Verify the token exists
- Hash the incoming token and compare to stored hash
- Check expiry
- Check it hasn’t already been used
- If valid, show a password reset form
5) Set the new password
When the form is submitted:
- Enforce password policy
- Hash the new password with a strong algorithm like:
- Argon2id preferred
- or bcrypt/scrypt if needed
- Mark the reset token as used immediately
- Invalidate any other active reset tokens for that user
6) Log the user in or require re-login
After reset:
- Either log the user in automatically, or
- Require them to sign in again
For higher security, it’s often better to:
- invalidate all existing sessions
- notify the user by email that the password was changed
Security checklist
Token security
- Use at least 32 bytes of random data
- Encode with URL-safe Base64 or hex
- Store only a hash of the token
- One token per request, one use only
Timing and leakage
- Always return the same response for:
- existing email
- non-existing email
- Avoid detailed error messages like “token invalid vs expired” unless needed
- Rate-limit reset requests by:
- IP
- email address
- device fingerprint if appropriate
Abuse prevention
- Add rate limiting and possibly CAPTCHA after repeated requests
- Monitor for spikes
- Consider cooldowns per account, e.g. no more than 1 email every few minutes
Session management
- After password reset:
- revoke all refresh tokens
- invalidate session cookies / server sessions
- rotate “remember me” tokens
- Notify the user if possible
Email deliverability
- Use a reputable email provider
- Set up:
- SPF
- DKIM
- DMARC
- Make sure reset emails are sent from a trusted domain
- Avoid spammy wording and excessive formatting
Good implementation pattern
Database table for reset tokens
Example fields:
user_idtoken_hashexpires_atused_atcreated_atrequest_ipuser_agent
Token handling
Pseudo-flow:
- Generate raw token
- Store
hash(token)in DB - Email raw token
- On submit, hash received token and look it up
- If valid, allow password reset
- Mark token used and invalidate sessions
Common mistakes to avoid
- Storing tokens in plaintext
- Tokens that never expire
- Allowing token reuse
- Revealing whether an email exists
- Sending reset links over insecure HTTP
- Failing to invalidate old sessions
- Using weak password hashing
- Not rate-limiting requests
- Putting sensitive info in query params without HTTPS
Extra hardening options
If your app is high-risk, consider:
- Re-authentication for critical changes
- MFA required before password reset completion
- Email notification after request and after completion
- Device/session history so users can spot suspicious activity
Minimal “best practice” version
If you want the shortest robust recipe:
- Ask for email
- Always show the same success message
- Generate secure random token
- Store hashed token with 30-minute expiry
- Email a reset link over HTTPS
- Validate token server-side
- Let user set new password
- Hash password with Argon2id
- Mark token used
- Revoke all sessions
- Notify user of the change
- Rate-limit requests
If you want, I can also provide:
- a database schema,
- backend pseudocode, or
- a complete implementation example in Node.js, Python, or Go.