cas_lib/password_hashers/
bcrypt.rs

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