@@ -15,6 +15,7 @@ use scrypt::Scrypt;
15
15
16
16
struct HashPack ( ) ;
17
17
18
+ // abstracted it in HashPack impl for struct
18
19
impl HashPack {
19
20
20
21
// TAKE: https://stackoverflow.com/posts/74954705/revisions
@@ -23,6 +24,7 @@ impl HashPack {
23
24
salt : & ' a SaltString ,
24
25
) -> Result < String , Error > //Result<PasswordHash<'a>, Error>
25
26
{
27
+ // obtain the hashed pw and match if it worked, on error return the error, on success return hash as String
26
28
let hashed_password = & Pbkdf2 . hash_password ( & bytes_to_hash, salt) ;
27
29
match hashed_password
28
30
{
@@ -38,6 +40,7 @@ impl HashPack {
38
40
// Trait objects for algorithms to support
39
41
let algs: & [ & dyn PasswordVerifier ] = & [ & Argon2 :: default ( ) , & Pbkdf2 , & Scrypt ] ;
40
42
43
+ // return true or false, if ok or not.
41
44
return match password_hash. verify_password ( algs, input_password)
42
45
{
43
46
Ok ( _) => true ,
@@ -48,17 +51,17 @@ impl HashPack {
48
51
49
52
fn main ( )
50
53
{
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
53
56
54
57
match hash
55
58
{
56
59
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
58
62
{
59
- println ! ( "Success 2221 " ) ;
63
+ println ! ( "Success Verify Hash " ) ;
60
64
}
61
- println ! ( "Success:{}" , h)
62
65
} ,
63
66
Err ( e) => println ! ( "Error: {}" , e)
64
67
} ;
0 commit comments