diff options
-rw-r--r-- | src/auth.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/auth.rs b/src/auth.rs index 94a2fda..48e36ce 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -62,10 +62,13 @@ pub fn match_auth(basic_auth: BasicAuthParams, required_auth: &RequiredAuth) -> } pub fn compare_hash<T: Digest>(password: String, hash: &String) -> bool { + get_hash_hex::<T>(password) == *hash +} + +fn get_hash_hex<T: Digest>(text: String) -> String { let mut hasher = T::new(); - hasher.input(password); - let received_hash = hex::encode(hasher.result()); - received_hash == *hash + hasher.input(text); + hex::encode(hasher.result()) } impl Middleware<crate::MiniserveConfig> for Auth { |