-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_hashing.rs
More file actions
28 lines (22 loc) · 870 Bytes
/
Copy pathpassword_hashing.rs
File metadata and controls
28 lines (22 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! Password hashing with Argon2id and scrypt.
//!
//! Run with:
//!
//! ```text
//! cargo run --example password_hashing --features password-hashing,getrandom
//! ```
use rscrypto::{Argon2idPassword, ScryptPassword};
fn main() -> Result<(), Box<dyn core::error::Error>> {
let password = b"correct horse battery staple";
let argon2 = Argon2idPassword::default();
let argon2_phc = argon2.hash_password(password)?;
assert!(argon2.verify_password(password, &argon2_phc).is_ok());
assert!(argon2.verify_password(b"wrong password", &argon2_phc).is_err());
let scrypt = ScryptPassword::default();
let scrypt_phc = scrypt.hash_password(password)?;
assert!(scrypt.verify_password(password, &scrypt_phc).is_ok());
assert!(scrypt.verify_password(b"wrong password", &scrypt_phc).is_err());
println!("{argon2_phc}");
println!("{scrypt_phc}");
Ok(())
}