hash_password

Function hash_password 

Source
pub fn hash_password(password: &str) -> Result<String>
Expand description

Hashes a password using bcrypt with a secure cost factor.

This function uses the bcrypt algorithm to hash passwords with a predefined cost factor. Bcrypt is designed to be computationally expensive to prevent brute-force attacks and includes automatic salt generation.

§Arguments

  • password - The plaintext password to hash

§Returns

  • Ok(String) - The bcrypt hash including salt and cost parameters
  • Err(AuthError) - If hashing fails or password is invalid

§Security Notes

  • Uses bcrypt’s default cost factor (currently 12)
  • Each hash includes a unique random salt
  • The same password will produce different hashes due to random salting
  • Empty passwords are rejected for security

§Example

use auth_framework::secure_utils::hash_password;

let password = "user_password_123";
let hash = hash_password(password).unwrap();
println!("Password hash: {}", hash);