@@ -396,8 +396,8 @@ public function postLogin()
396396 {
397397 $ max_login_attempts_2_show_captcha = $ this ->server_configuration_service ->getConfigValue ("MaxFailed.LoginAttempts.2ShowCaptcha " );
398398 $ max_login_failed_attempts = intval ($ this ->server_configuration_service ->getConfigValue ("MaxFailed.Login.Attempts " ));
399- $ login_attempts = 0 ;
400- $ username = '' ;
399+ $ login_attempts = ( int ) Session:: get ( ' captcha_failed_attempts ' , 0 ) ;
400+ $ username = '' ;
401401 $ user = null ;
402402
403403 try
@@ -411,7 +411,6 @@ public function postLogin()
411411 if (isset ($ data ['password ' ]))
412412 $ data ['password ' ] = trim ($ data ['password ' ]);
413413
414- $ login_attempts = intval (Request::input ('login_attempts ' ));
415414 // Build the validation constraint set.
416415 $ rules = [
417416 'username ' => 'required|email ' ,
@@ -436,7 +435,10 @@ public function postLogin()
436435 $ connection = $ data ['connection ' ] ?? null ;
437436
438437 try {
438+ $ user = $ this ->auth_service ->getUserByUsername ($ username );
439439 if ($ flow == "password " && $ this ->auth_service ->login ($ username , $ password , $ remember )) {
440+ Session::forget ('captcha_failed_attempts ' );
441+ Session::save ();
440442 return $ this ->login_strategy ->postLogin ();
441443 }
442444
@@ -468,15 +470,18 @@ public function postLogin()
468470
469471 $ otpClaim = OAuth2OTP::fromParams ($ username , $ connection , $ password );
470472 $ this ->auth_service ->loginWithOTP ($ otpClaim , $ client );
473+ Session::forget ('captcha_failed_attempts ' );
474+ Session::save ();
471475 return $ this ->login_strategy ->postLogin ();
472476 }
473477 } catch (AuthenticationException $ ex ) {
474478 // failed login attempt...
475479
476- $ user = $ this ->auth_service ->getUserByUsername ($ username );
477- if (!is_null ($ user )) {
478- $ login_attempts = $ user ->getLoginFailedAttempt ();
479- }
480+ $ login_attempts = $ login_attempts + 1 ;
481+ Session::put ('captcha_failed_attempts ' , $ login_attempts );
482+ Session::save ();
483+
484+ // User.loginFailedAttempt drives account lockout (persisted by auth_service).
480485
481486 return $ this ->login_strategy ->errorLogin
482487 (
@@ -525,6 +530,9 @@ public function postLogin()
525530 Log::warning ($ ex1 );
526531
527532 $ user = $ this ->auth_service ->getUserByUsername ($ username );
533+ $ login_attempts = $ login_attempts + 1 ;
534+ Session::put ('captcha_failed_attempts ' , $ login_attempts );
535+ Session::save ();
528536
529537 $ response_data = [
530538 'max_login_attempts_2_show_captcha ' => $ max_login_attempts_2_show_captcha ,
0 commit comments