Project

General

Profile

Actions

Sub-Task #184

open

Epic #3: Implement a secure user authentication system

Feature #162: Password Recovery

User Story #183: As a user, I want to request a password reset, so that I can recover my account

Generate reset token and send reset email

Sub-Task #184: Generate reset token and send reset email

Added by Bricklou 8 months ago. Updated 23 days ago.

Status:
Done
Priority:
Normal
Assigned To:
Target version:
Start date:
11/02/2026
Due date:
% Done:

100%

Estimated time:

Description

Server side of the reset request (#183).

Endpoint

  • POST /api/v1/authentication/forgot-password, body { email }.
  • Always answers 202 with a MessageResponse, whether the account exists or not.
  • Rate limited: 3 requests per hour per email (lowercased), plus the per-IP login limiter. 429 with Retry-After when exceeded.

Flow

  • The route publishes a PasswordResetRequested { email } event and returns. The token never travels on the event bus.
  • The worker looks the user up by email. It sends a mail only if the account has a password and a verified email; otherwise it does nothing.
  • Token: 32 random bytes, base64url. Only its SHA-256 hash is stored.
  • Table password_resets: user_id (PK, FK to users, cascade), token_hash (unique), created_at, expires_at. One row per user: a new request deletes the previous one in the same transaction.
  • Link: {base_url}/auth/reset-password#token=... (fragment, not query string).
  • Template password_reset.mjml, same layout as email_verification.mjml.
  • A failed send returns an error so the bus retries.

Implementation

  • New feature features/password_reset/, same layout as features/email_verification/ (db, service, events, event_handlers, mail, error). Handlers registered in worker/register.rs.
  • Migration and entity through the db-migration skill.
  • OpenAPI response schemas through the openapi-response-schema skill.

Tests

  • Service: token issued, previous token replaced, no token for unknown email, no password, or unverified email.
  • Route: same 202 for known and unknown emails, 429 after the limit.
  • Mail: recording sender receives one mail with the link.
Actions

Also available in: PDF Atom