Overview

The update_password function changes a user’s password.

Function Signature

pub async fn update_password(
    user_id: &str,
    request: UpdatePasswordRequest
) -> Result<()>

Parameters

user_id
&str
required
The unique identifier of the user
request
UpdatePasswordRequest
required
Password update request containing:
  • current_password: Current password (required for verification)
  • new_password: New password to set (required)

Return Value

Returns Result<()> indicating success or failure.

Basic Usage

use wacht::api::users::*;

let password_update = UpdatePasswordRequest {
    current_password: "old-password-123".to_string(),
    new_password: "new-secure-password-456".to_string(),
};

update_password("52057194421551105", password_update).await?;
println!("Password updated successfully");

Error Handling

match update_password("52057194421551105", request).await {
    Ok(()) => {
        println!("Password updated successfully");
        println!("User should be notified via email");
    }
    Err(Error::Api { status, message, .. }) => {
        match status.as_u16() {
            404 => println!("User not found"),
            401 => println!("Current password incorrect"),
            400 => println!("Invalid password: {}", message),
            403 => println!("Access denied: {}", message),
            _ => println!("API error {}: {}", status, message),
        }
    }
    Err(e) => println!("Request failed: {}", e),
}

Security Notes

  • Passwords must meet minimum security requirements
  • Current password is required for verification
  • Password history may prevent reuse of recent passwords
  • Users are typically notified via email after password changes

Rate Limits

  • Password operations: 10 requests per minute per user
  • Burst limit: 3 requests per second