1 extern crate argon2rs;
2 use argon2rs::verifier::Encoded;
3 use argon2rs::defaults::{KIB, LANES, PASSES};
4 use argon2rs::{Argon2, Variant};
5
main()6 pub fn main() {
7 // A typical password hashing scenario:
8 //
9 // 1. Hash a password into a secure, storable encoding:
10 let a2 = Argon2::new(PASSES, LANES, KIB, Variant::Argon2i).unwrap();
11 let enc0 = Encoded::new(a2,
12 b"password goes here",
13 b"sodium chloride",
14 b"",
15 b"");
16 let bytes0 = enc0.to_u8();
17 println!("storable encoding 0: {}",
18 String::from_utf8(bytes0.clone()).unwrap());
19
20 // or, if you're in a hurry and/or would rather rely on algorithm defaults:
21 let bytes1 = Encoded::default2i(b"another password",
22 b"salt required",
23 b"key",
24 b"")
25 .to_u8();
26 println!("storable encoding 1: {}",
27 String::from_utf8(bytes1.clone()).unwrap());
28
29 // 2. Verify later-received input against a previously created encoding.
30 let enc0 = Encoded::from_u8(&bytes0[..]).unwrap();
31 assert!(enc0.verify(b"password goes here"));
32
33 let enc1 = Encoded::from_u8(&bytes1[..]).unwrap();
34 assert!(enc1.verify(b"another password"));
35 }
36