Enum htpasswd_verify::Hash
source · pub enum Hash<'a> {
MD5(MD5Hash<'a>),
BCrypt(Cow<'a, str>),
SHA1(Cow<'a, str>),
Crypt(Cow<'a, str>),
}
Variants§
Implementations§
source§impl<'a> Hash<'a>
impl<'a> Hash<'a>
pub fn check<S: AsRef<str>>(&self, password: S) -> bool
sourcepub fn parse(hash: &'a str) -> Hash<'a>
pub fn parse(hash: &'a str) -> Hash<'a>
Parses the hash part of the htpasswd entry.
Example:
use htpasswd_verify::{Hash, MD5Hash};
let entry = "user:$apr1$lZL6V/ci$eIMz/iKDkbtys/uU7LEK00";
let semicolon = entry.find(':').unwrap();
let username = &entry[..semicolon];
let hash_id = &entry[(semicolon + 1)..];
assert_eq!(hash_id, "$apr1$lZL6V/ci$eIMz/iKDkbtys/uU7LEK00");
let hash = Hash::parse(hash_id);
assert_eq!(
hash,
Hash::MD5(MD5Hash {
salt: "lZL6V/ci".into(),
hash: "eIMz/iKDkbtys/uU7LEK00".into(),
},
));