Skip to main content

verify_password_bcrypt

Function verify_password_bcrypt 

Source
pub fn verify_password_bcrypt(password: &str, hash: &str) -> Result<bool>
Expand description

Verifies a plaintext password against a bcrypt hash.

This function uses bcrypt to verify that a plaintext password matches a previously generated hash. The verification is performed in constant time to prevent timing attacks.

§Arguments

  • password - The plaintext password to verify
  • hash - The bcrypt hash to verify against

§Returns

  • Ok(true) if the password matches the hash
  • Ok(false) if the password does not match the hash
  • Err(AuthError) if verification fails due to an invalid hash format

§Security Notes

  • Verification is performed in constant time
  • The hash must be a valid bcrypt hash including salt and cost parameters
  • Invalid hash formats will result in an error rather than false

§Example

use auth_framework::security::secure_utils::{hash_password_bcrypt, verify_password_bcrypt};

let password = "user_password_123";
let hash = hash_password_bcrypt(password).unwrap();

assert!(verify_password_bcrypt(password, &hash).unwrap());
assert!(!verify_password_bcrypt("wrong_password", &hash).unwrap());