mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
rename password-related utils functions
This commit is contained in:
parent
aa4cd8b1e1
commit
71f3d84115
5 changed files with 7 additions and 7 deletions
|
|
@ -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(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::forbidden(),
|
ErrorKind::forbidden(),
|
||||||
"Wrong username or password.",
|
"Wrong username or password.",
|
||||||
|
|
|
||||||
|
|
@ -586,7 +586,7 @@ impl KeyValueDatabase {
|
||||||
|
|
||||||
let empty_hashed_password = password
|
let empty_hashed_password = password
|
||||||
.map_or(false, |password| {
|
.map_or(false, |password| {
|
||||||
utils::verify_password_hash("", password)
|
utils::verify_password("", password)
|
||||||
});
|
});
|
||||||
|
|
||||||
if empty_hashed_password {
|
if empty_hashed_password {
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ impl service::users::Data for KeyValueDatabase {
|
||||||
password: Option<&str>,
|
password: Option<&str>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if let Some(password) = password {
|
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
|
self.userid_password
|
||||||
.insert(user_id.as_bytes(), hash.as_bytes())?;
|
.insert(user_id.as_bytes(), hash.as_bytes())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ impl Service {
|
||||||
|
|
||||||
// Check if password is correct
|
// Check if password is correct
|
||||||
if let Some(hash) = services().users.password_hash(&user_id)? {
|
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 =
|
uiaainfo.auth_error =
|
||||||
Some(ruma::api::client::error::StandardErrorBody {
|
Some(ruma::api::client::error::StandardErrorBody {
|
||||||
kind: ErrorKind::forbidden(),
|
kind: ErrorKind::forbidden(),
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,8 @@ pub(crate) fn random_string(length: usize) -> String {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate a new hash for the given password
|
/// Hash the given password
|
||||||
pub(crate) fn calculate_password_hash<B>(
|
pub(crate) fn hash_password<B>(
|
||||||
password: B,
|
password: B,
|
||||||
) -> Result<password_hash::PasswordHashString, password_hash::Error>
|
) -> Result<password_hash::PasswordHashString, password_hash::Error>
|
||||||
where
|
where
|
||||||
|
|
@ -89,7 +89,7 @@ where
|
||||||
/// Compare a password to a hash
|
/// Compare a password to a hash
|
||||||
///
|
///
|
||||||
/// Returns `true` if the password matches the hash, `false` otherwise.
|
/// Returns `true` if the password matches the hash, `false` otherwise.
|
||||||
pub(crate) fn verify_password_hash<S, B>(hash: S, password: B) -> bool
|
pub(crate) fn verify_password<S, B>(hash: S, password: B) -> bool
|
||||||
where
|
where
|
||||||
S: AsRef<str>,
|
S: AsRef<str>,
|
||||||
B: AsRef<[u8]>,
|
B: AsRef<[u8]>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue