cas_lib/password_hashers/bcrypt.rs
1
2
3use bcrypt::{hash, verify, DEFAULT_COST};
4
5use super::cas_password_hasher::CASPasswordHasher;
6
7pub struct CASBCrypt;
8
9impl CASPasswordHasher for CASBCrypt {
10 /// Hashes a password using bcrypt.
11 /// Returns the hashed password as a string.
12 fn hash_password(password_to_hash: String) -> String {
13 return hash(password_to_hash, DEFAULT_COST).unwrap();
14 }
15
16 /// Verifies a password against a hashed password using bcrypt.
17 /// Returns true if the password matches the hashed password, false otherwise.
18 fn verify_password(hashed_password: String, password_to_verify: String) -> bool {
19 return verify(password_to_verify, &hashed_password).unwrap();
20 }
21}