Store hashed passwords (#7)
Use if let instead of unwrap Default to invalid password if could not calculate Move hash password methdo and return Result Rename get_password method Default to empty password when no pwd is received Store hashed passwords Store passwords hashed with Argon2 and verify password with that stored hash. Co-authored-by: Guillem Nieto <gnieto.talo@gmail.com>
This commit is contained in:
parent
abcce95dd8
commit
fa9e127a1e
6 changed files with 148 additions and 21 deletions
|
@ -36,10 +36,10 @@ impl Data {
|
|||
}
|
||||
|
||||
/// Create a new user account by assigning them a password.
|
||||
pub fn user_add(&self, user_id: &UserId, password: Option<String>) {
|
||||
pub fn user_add(&self, user_id: &UserId, hash: &str) {
|
||||
self.db
|
||||
.userid_password
|
||||
.insert(user_id.to_string(), &*password.unwrap_or_default())
|
||||
.insert(user_id.to_string(), hash)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
@ -61,8 +61,8 @@ impl Data {
|
|||
.collect()
|
||||
}
|
||||
|
||||
/// Checks if the given password is equal to the one in the database.
|
||||
pub fn password_get(&self, user_id: &UserId) -> Option<String> {
|
||||
/// Gets password hash for given user id.
|
||||
pub fn password_hash_get(&self, user_id: &UserId) -> Option<String> {
|
||||
self.db
|
||||
.userid_password
|
||||
.get(user_id.to_string())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue