Skip to content

Commit 788f822

Browse files
authored
add comments
1 parent 05ed635 commit 788f822

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

passwordHashing.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use scrypt::Scrypt;
1515

1616
struct HashPack();
1717

18+
// abstracted it in HashPack impl for struct
1819
impl HashPack {
1920

2021
// TAKE: https://stackoverflow.com/posts/74954705/revisions
@@ -23,6 +24,7 @@ impl HashPack {
2324
salt: &'a SaltString,
2425
) -> Result<String, Error> //Result<PasswordHash<'a>, Error>
2526
{
27+
// obtain the hashed pw and match if it worked, on error return the error, on success return hash as String
2628
let hashed_password = &Pbkdf2.hash_password(&bytes_to_hash, salt);
2729
match hashed_password
2830
{
@@ -38,6 +40,7 @@ impl HashPack {
3840
// Trait objects for algorithms to support
3941
let algs: &[&dyn PasswordVerifier] = &[&Argon2::default(), &Pbkdf2, &Scrypt];
4042

43+
// return true or false, if ok or not.
4144
return match password_hash.verify_password(algs, input_password)
4245
{
4346
Ok(_) => true,
@@ -48,17 +51,17 @@ impl HashPack {
4851

4952
fn main ()
5053
{
51-
let salt = SaltString::generate(&mut OsRng);
52-
let hash = HashPack::get_passwordhash_object(input.field.as_bytes(), &salt);
54+
let salt = SaltString::generate(&mut OsRng); // Generate a random salt using OS (secure?) Random Number Generator (RNG)
55+
let hash = HashPack::get_passwordhash_object(input.field.as_bytes(), &salt); // call get_pw_hash_obj here, input is your plaintext pw -> bytes
5356

5457
match hash
5558
{
5659
Ok(h) => {
57-
if HashPack::verify_hash(input.field, &h)
60+
println!("Success Hashing:{}", h)
61+
if HashPack::verify_hash(input.field, &h) // call the Hashpack -> verify_hash func input.field is your plaintext pw, h is your hash
5862
{
59-
println!("Success 2221");
63+
println!("Success Verify Hash");
6064
}
61-
println!("Success:{}", h)
6265
},
6366
Err(e) => println!("Error: {}", e)
6467
};

0 commit comments

Comments
 (0)