Skip to content

Commit 7946552

Browse files
committed
Fix
1 parent 24eedd6 commit 7946552

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

server/src/handlers/http/rbac.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ pub async fn reset_password(username: web::Path<String>) -> Result<impl Responde
6565
return Err(RBACError::UserDoesNotExist);
6666
}
6767
// get new password for this user
68-
let PassCode { password, hashcode } = User::gen_new_password();
68+
let PassCode { password, hash } = User::gen_new_password();
6969
// update parseable.json first
7070
let mut metadata = get_metadata().await?;
7171
if let Some(user) = metadata
7272
.users
7373
.iter_mut()
7474
.find(|user| user.username == username)
7575
{
76-
user.password = hashcode.clone();
76+
user.password_hash = hash.clone();
7777
} else {
7878
// should be unreachable given state is always consistent
7979
return Err(RBACError::UserDoesNotExist);
@@ -86,7 +86,7 @@ pub async fn reset_password(username: web::Path<String>) -> Result<impl Responde
8686
.unwrap()
8787
.get_mut(&username)
8888
.expect("checked that user exists in map")
89-
.password = hashcode;
89+
.password_hash = hash;
9090

9191
Ok(password)
9292
}

server/src/rbac/user.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ use crate::option::CONFIG;
3030
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
3131
pub struct User {
3232
pub username: String,
33-
pub password: String,
33+
pub password_hash: String,
3434
// fill this
3535
pub role: Vec<()>,
3636
}
3737

3838
impl User {
3939
// create a new User and return self with password generated for said user.
4040
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();
4242
(
4343
Self {
4444
username,
45-
password: hashcode,
45+
password_hash: hash,
4646
role: Vec::new(),
4747
},
4848
password,
@@ -53,7 +53,7 @@ impl User {
5353
// $<id>[$v=<version>][$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]]
5454
// ref https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md#specification
5555
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();
5757
Argon2::default()
5858
.verify_password(password.as_bytes(), &parsed_hash)
5959
.is_ok()
@@ -62,8 +62,8 @@ impl User {
6262
// gen new password
6363
pub fn gen_new_password() -> PassCode {
6464
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 }
6767
}
6868
}
6969

@@ -89,7 +89,7 @@ impl UserMap {
8989

9090
pub struct PassCode {
9191
pub password: String,
92-
pub hashcode: String,
92+
pub hash: String,
9393
}
9494

9595
pub fn get_admin_user() -> User {
@@ -99,7 +99,7 @@ pub fn get_admin_user() -> User {
9999

100100
User {
101101
username,
102-
password: hashcode,
102+
password_hash: hashcode,
103103
role: Vec::new(),
104104
}
105105
}

0 commit comments

Comments
 (0)