Function firebase_scrypt::verify_password
source · pub fn verify_password(
password: &str,
known_hash: &str,
salt: &str,
salt_separator: &str,
signer_key: &str,
rounds: u32,
mem_cost: u32
) -> Result<bool, GenerateHashError>
Expand description
Verifies the password with a given known hash.
In case the salt separator, signer key, number of rounds and cost of memory don’t change in
runtime, you may want to use the FirebaseScrypt
struct to manage them.
Example
use firebase_scrypt::verify_password;
const SALT_SEPARATOR: &str = "Bw==";
const SIGNER_KEY: &str = "jxspr8Ki0RYycVU8zykbdLGjFQ3McFUH0uiiTvC8pVMXAn210wjLNmdZJzxUECKbm0QsEmYUSDzZvpjeJ9WmXA==";
const ROUNDS: u32 = 8;
const MEM_COST: u32 = 14;
let password = "user1password";
let salt = "42xEC+ixf3L2lw==";
let password_hash ="lSrfV15cpx95/sZS2W9c9Kp6i/LVgQNDNC/qzrCnh1SAyZvqmZqAjTdn3aoItz+VHjoZilo78198JAdRuid5lQ==";
let is_valid = verify_password(
password,
password_hash,
salt,
SALT_SEPARATOR,
SIGNER_KEY,
ROUNDS,
MEM_COST,
).unwrap();
assert!(is_valid)