48 - Password Reset
Overview
Architecture Diagram
┌──────────────────────────────────────────────────────────────────────────────┐
│ Password Reset Architecture │
└──────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────┐
│ Step 1: Initiate Reset │
│ /forgot-password │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ User enters email address │ │
│ │ │ │
│ │ Email: [[email protected] ] │ │
│ │ │ │
│ │ [Send Reset Link] │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ Validate email exists │
│ │ │
│ ┌─────────────────────┴─────────────────────┐ │
│ │ │ │
│ Email Found Not Found │
│ │ │ │
│ ▼ ▼ │
│ Generate reset token Show generic message │
│ Store in database (prevent enumeration) │
│ Send email with link │
└─────────────────────────────────────────────────────────────────────────────┘
│
│ User clicks email link
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Step 2: Verify Identity │
│ /reset-password?token=xxx │
│ │
│ Validate reset token │
│ │ │
│ ┌─────────────────────┴─────────────────────┐ │
│ │ │ │
│ Token Valid Token Invalid/Expired │
│ │ │ │
│ ▼ ▼ │
│ Check if TOTP enabled Show error message │
│ │ │
│ ┌─────────┴─────────┐ │
│ │ │ │
│ TOTP Enabled No TOTP │
│ │ │ │
│ ▼ ▼ │
│ Show TOTP Form Show Password Form │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
│
│ After verification
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Step 3: Set New Password │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ New Password: [•••••••••••••••• ] │ │
│ │ Confirm Password: [•••••••••••••••• ] │ │
│ │ │ │
│ │ Requirements: │ │
│ │ ✓ At least 8 characters │ │
│ │ ✓ Contains uppercase letter │ │
│ │ ✓ Contains lowercase letter │ │
│ │ ✓ Contains number │ │
│ │ ✓ Contains special character │ │
│ │ │ │
│ │ [Reset Password] │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ Hash password with Argon2 + pepper │
│ Update user record │
│ Invalidate reset token │
│ Invalidate all sessions │
│ Redirect to login │
│ │
└─────────────────────────────────────────────────────────────────────────────┘Database Schema
password_reset_tokens Table
Token Generation
Secure Token Creation
Token Validation
Password Security
Argon2 Hashing with Pepper
Password Requirements
TOTP Integration
Reset with 2FA
API Endpoints
Request Reset
Validate Token
Reset Password
Reset Flow Implementation
Full Reset Service
Security Measures
Rate Limiting
Audit Logging
Token Security
Measure
Implementation
Frontend Components
Forgot Password Form
Reset Password Form
Key Files Reference
File
Purpose
Last updated