Prompt

How do I handle password reset and email verification securely?

Technology / Identity & Access1 observationLast seen Oct 6, 2026

Latest observation

Oct 6, 2026OpenAI APIWeb search: off

To handle password reset and email verification securely, treat both flows as one-time, short-lived, hard-to-guess token problems with careful expiration, storage, and response behavior.

Core principles

  1. Use cryptographically secure random tokens

    • Generate tokens with a CSPRNG.
    • Use at least 128 bits of entropy (more is fine).
  2. Store only a hashed version of the token

    • If your database leaks, raw reset/verification tokens shouldn’t be usable.
    • Store hash(token) rather than the token itself, similar to passwords.
  3. Make tokens single-use and short-lived

    • Password reset: typically 15–60 minutes.
    • Email verification: often 24 hours or less, depending on UX.
    • Invalidate tokens after successful use.
  4. Bind tokens to purpose

    • A reset token should only work for password resets.
    • A verification token should only work for email verification.
    • Include a type/purpose field server-side.
  5. Don’t reveal whether an account exists

    • For “forgot password,” always respond with something like:
      • “If an account exists for that email, we’ve sent instructions.”
    • This prevents account enumeration.
  6. Use HTTPS everywhere

    • Tokens in links must only travel over TLS.
  7. Limit token reuse and scope

    • One token, one action, one account.
    • Rotate/invalidate any older outstanding tokens when issuing a new one, if appropriate.
  8. Add rate limiting and abuse controls

    • Rate limit requests by email, IP, and device fingerprint if appropriate.
    • Add CAPTCHA or stronger friction for suspicious patterns.

Password reset flow

Recommended flow

  1. User submits email.
  2. Server always returns a generic success response.
  3. If the email exists:
    • Generate a random reset token.
    • Store a hash of the token with:
      • user ID
      • purpose = password_reset
      • expiry timestamp
      • used flag = false
    • Send email containing a link like:
      • https://example.com/reset-password?token=...
  4. User clicks link and submits a new password.
  5. Server:
    • Hashes incoming token
    • Finds matching record
    • Verifies not expired and not used
    • Verifies associated account is still valid
    • Updates password using a strong password hash like Argon2id, bcrypt, or scrypt
    • Marks token as used
    • Optionally invalidates all other sessions and reset tokens

Extra protections

  • Invalidate active sessions after password change if that fits your threat model.
  • Consider requiring the user to re-authenticate for sensitive changes after reset.
  • Don’t allow reset tokens to be used to change email or other profile data.

Email verification flow

Recommended flow

  1. User signs up or changes email.
  2. Generate verification token.
  3. Store hashed token with purpose = email_verification, expiry, used flag.
  4. Send email with verification link.
  5. On click:
    • Verify token and expiry
    • Mark email as verified
    • Mark token as used

Extra protections

  • If the email address changes, treat the new email as unverified until confirmed.
  • Don’t verify an email just because the account was created.
  • If the user requests multiple verification emails, consider invalidating prior ones.

Token design options

Opaque token

  • Random string stored hashed in DB.
  • Simple and common.
  • Best default choice.

Signed token

  • Includes data like user ID and expiry in a signed payload.
  • Can reduce DB lookups, but:
    • harder to revoke
    • more complex
    • must be carefully designed
  • For password reset and verification, opaque tokens are usually safer and simpler.

Practical implementation tips

  • Use a strong password hashing algorithm for passwords:
    • Argon2id preferred
  • Use a strong hash like SHA-256 or HMAC-SHA-256 for token storage
    • If using SHA-256, consider a server-side secret (“pepper”) or HMAC
  • Normalize emails consistently before lookup:
    • trim whitespace
    • lowercase domain, and usually the whole address for lookup purposes
  • Be careful with link scanners:
    • Some email security tools may prefetch links.
    • A common mitigation is to make the GET link open a confirmation page, and require a POST or second step to finalize reset/verification.

Common mistakes to avoid

  • Storing reset tokens in plaintext
  • Long-lived tokens
  • Reusing the same token for multiple purposes
  • Returning “email not found” on forgot-password
  • Putting sensitive actions on GET without a follow-up confirmation step
  • Logging tokens in application logs or analytics
  • Using weak randomness like Math.random()
  • Not invalidating sessions after a password reset

A good secure baseline

  • Random 32-byte token
  • Hash token before storing
  • 15–30 minute reset expiry
  • 24-hour verification expiry
  • One-time use
  • Generic user-facing responses
  • HTTPS
  • Rate limiting
  • Argon2id password hashing
  • Session invalidation after reset

If you want, I can also give you:

  1. a reference database schema,
  2. example code in Node/Python/Go, or
  3. a full secure flow diagram for both features.

Brands

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.