use crate::Result;
use argon2::password_hash::Error;
use password_hash::PasswordVerifier;
use std::convert::identity;
pub async fn verify<'a>(password: String, hash: String) -> Result<bool> {
let hasher = crate::get_hasher().await?;
let res = tokio::task::spawn_blocking(move || {
password_hash::PasswordHash::try_from(hash.as_ref())
.map(|hash| hasher.verify_password(password.as_bytes(), &hash))
.and_then(identity)
})
.await?;
match res {
Ok(()) => Ok(true),
Err(Error::Password) => Ok(false),
Err(e) => Err(e.into()),
}
}