Authentication
Change Password
Update the authenticated user password
PUT
Change Password
Overview
Allows an authenticated user to change their password. Requires the current password for verification and enforces security requirements on the new password.Authentication
Required: Bearer token in Authorization headerRequest Body
The user’s current password for verification
The new password. Must meet security requirements:
- Minimum 8 characters
- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one special character
Response
Indicates if the password was updated successfully
Confirmation message
Always null for password change responses
Examples
Response Examples
Success (200 OK)
Missing Fields (400)
Weak Password (400)
Incorrect Current Password (401)
User Not Found (404)
Error Responses
| Status Code | Description |
|---|---|
| 400 | Missing fields or password doesn’t meet security requirements |
| 401 | Invalid token or incorrect current password |
| 404 | User account not found |
| 500 | Internal server error |
Password Requirements
All passwords must meet these security criteria:
- Length: Minimum 8 characters
- Uppercase: At least one (A-Z)
- Lowercase: At least one (a-z)
- Number: At least one (0-9)
- Special Character: At least one (!@#$%^&*()_+-=[]|;:,.?)
Security Notes
Password Verification
Password Verification
The API verifies the current password using bcrypt before allowing the change. This prevents unauthorized password changes if a token is compromised but the attacker doesn’t know the password.
Password Hashing
Password Hashing
New passwords are hashed using bcrypt with 10 salt rounds before storage. Passwords are never stored in plain text.
Session Continuity
Session Continuity
After changing the password, the current JWT token remains valid until expiration. The user does not need to log in again immediately.
Best Practices
Best Practices
- Require password confirmation on the client side before submitting
- Display password strength indicators to users
- Consider implementing password history to prevent reuse
- Log password change events for security auditing
Related Endpoints
Update Profile
Update name and email information
Login
Log in with new password
Source Code Reference
- Route:
src/routes/auth.routes.js:371 - Controller:
src/controllers/authController.js:changePassword - Validation:
src/utils/validators.util.js:isValidPassword
Change Password
