Skip to content

Commit

Permalink
Prevent password timing attack
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMoolenaar committed Nov 18, 2024
1 parent 543ed36 commit 4f51b1e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/routes/auth/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ pub async fn login_post(
.unwrap();

if user.is_none() {
// Prevent unknown email from returning faster than providing a known email.
// This way, it cannot be known if the email exists.
let password_hash = PasswordHash::new("something").unwrap();
let _ = Argon2::default().verify_password(b"anything", &password_hash).is_ok();

errors.insert("general", "Invalid email or password");
return (
StatusCode::UNAUTHORIZED,
Expand Down

0 comments on commit 4f51b1e

Please sign in to comment.