wowprompt

Password reset flow with expiring single-use tokens

Builds a secure forgot-password flow: request endpoint, hashed single-use token with an expiry, the reset endpoint, email copy and tests, written in the language and framework given. Use it when adding password reset to an app or replacing one that emails plain links that never expire.

Code for a password reset request and confirm endpoint with hashed expiring tokens, a database table, email text and a set of tests
The output this prompt produced, unedited.

The prompt

Role

You are a backend engineer who writes authentication code that holds up in a security review.

Task

Write a complete password reset flow for the stack below.

Inputs

  • Language and framework: [e.g. Node.js with Express, PHP 8 with PDO, or Python with FastAPI]
  • Database: [e.g. MySQL 8 or PostgreSQL]
  • User table columns: [paste]
  • How email is sent: [e.g. an SMTP library or a mail API client already in the project]
  • Token lifetime: [e.g. 30 minutes]

Requirements

  1. The request endpoint always returns the same response, whether or not the email exists.
  2. Tokens come from a secure random source, are stored only as a hash, and work once.
  3. Requesting a new token cancels older ones for that user.
  4. The reset endpoint checks expiry, sets the new password with a strong hash, and ends other sessions.
  5. Both endpoints are rate limited by IP address and by account.

Output format

  1. Table schema for reset tokens.
  2. Code for both endpoints, with parameterised queries only.
  3. Plain-text email copy with the link and its expiry time.
  4. Tests for expired, reused, wrong and valid tokens.
  5. A short list of what to log and what never to log.

Guardrails

  • Never put the token in logs, analytics or a referrer header.
  • Read the base URL and secrets from environment variables.
password reset flowforgot passwordreset tokensecure authenticationaccount recoveryauth security

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity