Endpoint
Change the password for the currently authenticated user
Authentication
This endpoint requires authentication. Include a valid JWT token in the
Authorization header.Request Body
The user’s current password for verification
The new password to set. Should meet minimum security requirements.
Response
Indicates whether the password change was successful
Human-readable message describing the result
Example Request
Example Response
Success Response (200 OK)
Error Response (400 Bad Request)
Error Response (401 Unauthorized)
Error Codes
| Status Code | Description |
|---|---|
| 200 | Password changed successfully |
| 400 | Current password is incorrect |
| 401 | Not authenticated or invalid token |
| 422 | Validation error (e.g., weak password) |
| 500 | Internal server error |
Password Requirements
While not enforced by the API shown in the source code, follow these best practices:Password Security Guidelines
- Minimum 8 characters
- Mix of uppercase and lowercase letters
- At least one number
- At least one special character
- Should not match common passwords
- Should not contain user’s email or name
Implementation Details
The password change endpoint (fromapi_service.dart:60-82):
- Validates the current password on the backend
- If valid, updates to the new password
- Returns success status or error message
- Error messages can be in
messageorerrorfields
Common Errors
Current password is incorrect
Current password is incorrect
The
currentPassword field does not match the user’s actual password. The error message may be in Spanish: “La contraseña actual no es correcta”.Solution: Verify the user is entering their correct current password.Token expired or invalid
Token expired or invalid
The JWT token in the Authorization header is missing, malformed, or expired.Solution: Redirect the user to the login page to obtain a fresh token.
Connection error
Connection error
Network connectivity issues or backend unavailability.Solution: Display a user-friendly error message and allow retry. The error is caught as “Error de conexión al cambiar contraseña”.
Security Notes
- Always use HTTPS in production to protect credentials in transit
- The current password is verified before allowing changes
- Consider implementing rate limiting to prevent brute force attacks
- Log password change events for security auditing
- Consider requiring re-authentication after password change for sensitive accounts
Related Endpoints
- Login - Authenticate and obtain token
