Overview
The password recovery flow consists of three steps:- Request Reset Code: User provides email and receives a 6-digit verification code
- Verify Code: User submits the code to verify ownership of the email
- Reset Password: User provides the code and new password to complete the reset
Step 1: Request Reset Code
Request Body
Email address of the account to recover.
Response
Generic success message: “Si el correo existe, recibirás un código de recuperación”Note: The same message is returned whether the email exists or not to prevent email enumeration attacks.
Code Examples
Response Example
Success Response (200)
Error Responses
Missing Email (400)
Server Error (500)
Implementation Details
- Reset code is a 6-digit random number generated from Math.random()
- Code expires after exactly 30 minutes from generation
- In non-production environments, code is logged to console for testing
- Generic response prevents email enumeration attacks
- Source:
src/routes/users.js:87
Step 2: Verify Reset Code
Request Body
Email address of the account.
The 6-digit verification code received via email.
Response
Success message: “Código verificado exitosamente”
The user ID associated with the verified email. Can be used for additional verification in subsequent steps.
Code Examples
Response Example
Success Response (200)
Error Responses
Missing Fields (400)
Invalid Code (401)
Expired Code (401)
Server Error (500)
Implementation Details
- Validates both code match and expiration time
- Codes expire exactly 30 minutes after generation
- Verification success is logged with user ID for security auditing
- Source:
src/routes/users.js:125
Step 3: Reset Password
Request Body
Email address of the account.
The 6-digit verification code received via email.
New password for the account. Must be at least 6 characters long.
Response
Success message: “Contraseña actualizada exitosamente”
The user ID of the updated account.
The username of the updated account.
Code Examples
Response Example
Success Response (200)
Error Responses
Password Too Short (400)
Invalid Code (401)
Expired Code (401)
Server Error (500)
Implementation Details
- Password must be at least 6 characters long
- New password is hashed using bcrypt with 10 salt rounds before storage
- Reset code and expiry are cleared from database after successful reset
- Validates both code match and expiration time
- Password reset is logged with user ID for security auditing
- Source:
src/routes/users.js:156
Security Considerations
- Code Expiration: All reset codes expire after exactly 30 minutes
- Email Enumeration Prevention: Generic responses prevent attackers from determining valid email addresses
- Rate Limiting: Consider implementing rate limiting on these endpoints to prevent abuse
- HTTPS Only: All password recovery endpoints should only be accessible via HTTPS in production
- Logging: All verification and reset actions are logged with user IDs for security auditing