@@ -32,7 +32,8 @@ use zeroize::Zeroizing;
3232use super :: { MatrixError , MatrixJsonBody } ;
3333use crate :: {
3434 BoundActivityTracker , Limiter , METER , RequesterFingerprint , impl_from_error_for_route,
35- passwords:: PasswordManager , rate_limit:: PasswordCheckLimitedError ,
35+ passwords:: { PasswordManager , PasswordVerificationResult } ,
36+ rate_limit:: PasswordCheckLimitedError ,
3637} ;
3738
3839static LOGIN_COUNTER : LazyLock < Counter < u64 > > = LazyLock :: new ( || {
@@ -193,7 +194,7 @@ pub enum RouteError {
193194 NoPassword ,
194195
195196 #[ error( "password verification failed" ) ]
196- PasswordVerificationFailed ( # [ source ] anyhow :: Error ) ,
197+ PasswordVerificationFailed ,
197198
198199 #[ error( "request rate limited" ) ]
199200 RateLimited ( #[ from] PasswordCheckLimitedError ) ,
@@ -210,6 +211,12 @@ pub enum RouteError {
210211
211212impl_from_error_for_route ! ( mas_storage:: RepositoryError ) ;
212213
214+ impl From < anyhow:: Error > for RouteError {
215+ fn from ( err : anyhow:: Error ) -> Self {
216+ Self :: Internal ( err. into ( ) )
217+ }
218+ }
219+
213220impl IntoResponse for RouteError {
214221 fn into_response ( self ) -> axum:: response:: Response {
215222 let sentry_event_id =
@@ -241,7 +248,7 @@ impl IntoResponse for RouteError {
241248 error : "Missing property 'identifier" ,
242249 status : StatusCode :: BAD_REQUEST ,
243250 } ,
244- Self :: UserNotFound | Self :: NoPassword | Self :: PasswordVerificationFailed ( _ ) => {
251+ Self :: UserNotFound | Self :: NoPassword | Self :: PasswordVerificationFailed => {
245252 MatrixError {
246253 errcode : "M_FORBIDDEN" ,
247254 error : "Invalid username/password" ,
@@ -576,28 +583,32 @@ async fn user_password_login(
576583 // Verify the password
577584 let password = Zeroizing :: new ( password) ;
578585
579- let new_password_hash = password_manager
586+ match password_manager
580587 . verify_and_upgrade (
581588 & mut rng,
582589 user_password. version ,
583590 password,
584591 user_password. hashed_password . clone ( ) ,
585592 )
586- . await
587- . map_err ( RouteError :: PasswordVerificationFailed ) ?;
588-
589- if let Some ( ( version, hashed_password) ) = new_password_hash {
590- // Save the upgraded password if needed
591- repo. user_password ( )
592- . add (
593- & mut rng,
594- clock,
595- & user,
596- version,
597- hashed_password,
598- Some ( & user_password) ,
599- )
600- . await ?;
593+ . await ?
594+ {
595+ PasswordVerificationResult :: Success ( Some ( ( version, hashed_password) ) ) => {
596+ // Save the upgraded password if needed
597+ repo. user_password ( )
598+ . add (
599+ & mut rng,
600+ clock,
601+ & user,
602+ version,
603+ hashed_password,
604+ Some ( & user_password) ,
605+ )
606+ . await ?;
607+ }
608+ PasswordVerificationResult :: Success ( None ) => { }
609+ PasswordVerificationResult :: Failure => {
610+ return Err ( RouteError :: PasswordVerificationFailed ) ;
611+ }
601612 }
602613
603614 // We're about to create a device, let's explicitly acquire a lock, so that
0 commit comments