diff --git a/src/api/client_server/session.rs b/src/api/client_server/session.rs index 69e4cd9b..123a66c7 100644 --- a/src/api/client_server/session.rs +++ b/src/api/client_server/session.rs @@ -113,7 +113,7 @@ pub(crate) async fn login_route( )); } - if !utils::verify_password_hash(hash, password) { + if !utils::verify_password(hash, password) { return Err(Error::BadRequest( ErrorKind::forbidden(), "Wrong username or password.", diff --git a/src/database.rs b/src/database.rs index b53ab8a1..a9f2abc6 100644 --- a/src/database.rs +++ b/src/database.rs @@ -586,7 +586,7 @@ impl KeyValueDatabase { let empty_hashed_password = password .map_or(false, |password| { - utils::verify_password_hash("", password) + utils::verify_password("", password) }); if empty_hashed_password { diff --git a/src/database/key_value/users.rs b/src/database/key_value/users.rs index b0c209ce..3040e237 100644 --- a/src/database/key_value/users.rs +++ b/src/database/key_value/users.rs @@ -135,7 +135,7 @@ impl service::users::Data for KeyValueDatabase { password: Option<&str>, ) -> Result<()> { if let Some(password) = password { - if let Ok(hash) = utils::calculate_password_hash(password) { + if let Ok(hash) = utils::hash_password(password) { self.userid_password .insert(user_id.as_bytes(), hash.as_bytes())?; Ok(()) diff --git a/src/service/uiaa.rs b/src/service/uiaa.rs index 2a130896..109e214d 100644 --- a/src/service/uiaa.rs +++ b/src/service/uiaa.rs @@ -87,7 +87,7 @@ impl Service { // Check if password is correct if let Some(hash) = services().users.password_hash(&user_id)? { - if !utils::verify_password_hash(hash, password) { + if !utils::verify_password(hash, password) { uiaainfo.auth_error = Some(ruma::api::client::error::StandardErrorBody { kind: ErrorKind::forbidden(), diff --git a/src/utils.rs b/src/utils.rs index 9694595f..746d0b84 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -71,8 +71,8 @@ pub(crate) fn random_string(length: usize) -> String { .collect() } -/// Calculate a new hash for the given password -pub(crate) fn calculate_password_hash( +/// Hash the given password +pub(crate) fn hash_password( password: B, ) -> Result where @@ -89,7 +89,7 @@ where /// Compare a password to a hash /// /// Returns `true` if the password matches the hash, `false` otherwise. -pub(crate) fn verify_password_hash(hash: S, password: B) -> bool +pub(crate) fn verify_password(hash: S, password: B) -> bool where S: AsRef, B: AsRef<[u8]>,