From 2a6c7a566a89cded5eb9defdb05b3e510159bd93 Mon Sep 17 00:00:00 2001 From: indirection42 Date: Wed, 6 Mar 2024 15:42:51 +0800 Subject: [PATCH] Fix returned error caused by unknown username in validate credentials --- src/authentication/password.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/authentication/password.rs b/src/authentication/password.rs index 5c12360..45a7a37 100644 --- a/src/authentication/password.rs +++ b/src/authentication/password.rs @@ -58,11 +58,24 @@ pub async fn validate_credentials( expected_password_hash = stored_password_hash; } - spawn_blocking_with_tracing(move || { + match spawn_blocking_with_tracing(move || { verify_password_hash(expected_password_hash, credentials.password) }) .await - .context("Failed to spawn blocking task.")??; + .context("Failed to spawn blocking task.")? + { + Ok(_) => Ok(()), + Err(e) => match e { + AuthError::InvalidCredentials(_) => { + if user_id.is_none() { + Ok(()) + } else { + Err(e) + } + } + _ => Err(e), + }, + }?; user_id .ok_or_else(|| anyhow::anyhow!("Unknown username."))