Skip to main content

verify_password

Function verify_password 

Source
pub async fn verify_password(password: &str, hash: Option<&str>) -> bool
Expand description

Verifies a password against an Argon2id PHC hash, or None for an unknown account; unknown accounts verify against a dummy hash so response times do not reveal which accounts exist.

Runs on Tokio’s blocking pool: a verification takes tens of milliseconds of CPU, which on an async worker would stall every request that worker serves. One verification or hash per core runs at once, and the rest wait their turn.

let staff = Staff::filter_by_email(login).first().exec(&mut db).await?;
if !verify_password(password, staff.as_ref().map(|s| s.password_hash.as_str())).await {
    return Ok(None);
}