Password Recovery Workflow
This workflow covers the complete password recovery process, from requesting a reset email to setting a new password. The flow includes email verification, time-limited reset tokens, and password complexity enforcement.
Step-by-Step Explanation
Requesting a Password Reset
- User clicks "Forgot Password" — On the login page, the user clicks the "Forgot Password" link, which navigates them to the password recovery form.
- Enters email address — The user enters the email address associated with their TubeRaker account.
- API processes the request — A POST request is sent to
/auth/forgot-password. The server looks up the email in the database. - Security: silent failure — If the email is not found, the API still responds with a success message. This prevents email enumeration attacks where an attacker could probe for registered accounts.
- Reset email sent — If the email exists, the server generates a cryptographically secure reset token (valid for 1 hour) and sends it to the user's email as a clickable link.
Resetting the Password
- User clicks the reset link — The user opens the email and clicks the reset link, which contains the reset token as a URL parameter.
- Token validation — The server validates the reset token: it must exist, not be expired (1 hour limit), and not have been previously used. Invalid or expired tokens show an error with an option to request a new link.
- New password form — If the token is valid, the user is shown a form to enter a new password. The password must meet complexity requirements: minimum 12 characters, uppercase and lowercase letters, at least one number, and at least one special character.
- Password updated — Once the new password passes validation, the server hashes it with bcrypt and updates the user's record. The reset token is marked as used.
- Redirect to login — The user is redirected to the login page with a success message, where they can sign in with their new password.
Security Considerations
- Email enumeration prevention — The API always returns the same success response regardless of whether the email exists, preventing attackers from discovering valid accounts.
- Time-limited tokens — Reset tokens expire after 1 hour. Expired tokens cannot be used and the user must request a new reset link.
- Single-use tokens — Each reset token can only be used once. After a password is changed, the token is immediately invalidated.
- Password complexity — New passwords must meet strict complexity requirements (12+ characters, mixed case, numbers, special characters) to protect against brute-force attacks.