aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkhai96_ <hvksmr1996@gmail.com>2019-04-19 13:16:48 +0000
committerkhai96_ <hvksmr1996@gmail.com>2019-04-19 13:16:48 +0000
commit4c0ac05831ddc6933647a12cdbb56d9d8523b681 (patch)
tree6c38d0e70d99680082eb1eef05239ad449c24f9c /src
parentAdd support for sha-512 (diff)
downloadminiserve-4c0ac05831ddc6933647a12cdbb56d9d8523b681.tar.gz
miniserve-4c0ac05831ddc6933647a12cdbb56d9d8523b681.zip
Create get_hash_hex
Diffstat (limited to 'src')
-rw-r--r--src/auth.rs9
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 {