Skip to main content

Endpoint

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

string
required
The user’s current password for verification
string
required
The new password to set. Should meet minimum security requirements.

Response

boolean
required
Indicates whether the password change was successful
string
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

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 (from api_service.dart:60-82):
  1. Validates the current password on the backend
  2. If valid, updates to the new password
  3. Returns success status or error message
  4. Error messages can be in message or error fields
After changing the password, the user’s current session remains valid. The JWT token is not invalidated, so the user can continue using the application without re-logging in.

Common Errors

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.
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.
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
  • Login - Authenticate and obtain token