password-hash crateuse password_hash::PasswordHash;
use argon2::Argon2;
use pbkdf2::Pbkdf2;
use scrypt::Scrypt;
let hash_string = load_hash_string_for_user(...); // e.g. `$argon2id$...`
let input_password = read_password_from_user();
let password_hash = PasswordHash::new(&hash_string)
.expect("invalid password hash");
// Trait objects for algorithms to support
let algs = &[Argon2::default(), Pbkdf2, Scrypt];
if password_hash.verify_password(algs, input_password).is_ok() {
access_granted();
} else {
access_denied();
}
https://www.reddit.com/r/rust/comments/lgccv5/ysk_vscodes_most_recent_update_fixed_a_quirk_in/
原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。