@@ -30,19 +30,19 @@ use crate::option::CONFIG;
30
30
#[ derive( Debug , Clone , PartialEq , Eq , serde:: Serialize , serde:: Deserialize ) ]
31
31
pub struct User {
32
32
pub username : String ,
33
- pub password : String ,
33
+ pub password_hash : String ,
34
34
// fill this
35
35
pub role : Vec < ( ) > ,
36
36
}
37
37
38
38
impl User {
39
39
// create a new User and return self with password generated for said user.
40
40
pub fn create_new ( username : String ) -> ( Self , String ) {
41
- let PassCode { password, hashcode } = Self :: gen_new_password ( ) ;
41
+ let PassCode { password, hash } = Self :: gen_new_password ( ) ;
42
42
(
43
43
Self {
44
44
username,
45
- password : hashcode ,
45
+ password_hash : hash ,
46
46
role : Vec :: new ( ) ,
47
47
} ,
48
48
password,
@@ -53,7 +53,7 @@ impl User {
53
53
// $<id>[$v=<version>][$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]]
54
54
// ref https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md#specification
55
55
pub fn verify ( & self , password : & str ) -> bool {
56
- let parsed_hash = PasswordHash :: new ( & self . password ) . unwrap ( ) ;
56
+ let parsed_hash = PasswordHash :: new ( & self . password_hash ) . unwrap ( ) ;
57
57
Argon2 :: default ( )
58
58
. verify_password ( password. as_bytes ( ) , & parsed_hash)
59
59
. is_ok ( )
@@ -62,8 +62,8 @@ impl User {
62
62
// gen new password
63
63
pub fn gen_new_password ( ) -> PassCode {
64
64
let password = Alphanumeric . sample_string ( & mut rand:: thread_rng ( ) , 16 ) ;
65
- let hashcode = gen_hash ( & password) ;
66
- PassCode { password, hashcode }
65
+ let hash = gen_hash ( & password) ;
66
+ PassCode { password, hash }
67
67
}
68
68
}
69
69
@@ -89,7 +89,7 @@ impl UserMap {
89
89
90
90
pub struct PassCode {
91
91
pub password : String ,
92
- pub hashcode : String ,
92
+ pub hash : String ,
93
93
}
94
94
95
95
pub fn get_admin_user ( ) -> User {
@@ -99,7 +99,7 @@ pub fn get_admin_user() -> User {
99
99
100
100
User {
101
101
username,
102
- password : hashcode,
102
+ password_hash : hashcode,
103
103
role : Vec :: new ( ) ,
104
104
}
105
105
}
0 commit comments