From 4c0ac05831ddc6933647a12cdbb56d9d8523b681 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Fri, 19 Apr 2019 20:16:48 +0700 Subject: Create get_hash_hex --- src/auth.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/auth.rs') 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(password: String, hash: &String) -> bool { + get_hash_hex::(password) == *hash +} + +fn get_hash_hex(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 for Auth { -- cgit v1.2.3