Skip to content

Commit 1697b7a

Browse files
chore: increment/reset login_failed_attempt count
1 parent 48dd294 commit 1697b7a

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

app/Http/Controllers/UserController.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public function postLogin()
411411
if (isset($data['password']))
412412
$data['password'] = trim($data['password']);
413413

414-
$login_attempts = intval(Request::input('login_attempts'));
414+
$login_attempts = (int) Session::get('captcha_failed_attempts', 0);
415415
// Build the validation constraint set.
416416
$rules = [
417417
'username' => 'required|email',
@@ -436,7 +436,9 @@ public function postLogin()
436436
$connection = $data['connection'] ?? null;
437437

438438
try {
439+
$user = $this->auth_service->getUserByUsername($username);
439440
if ($flow == "password" && $this->auth_service->login($username, $password, $remember)) {
441+
$user->setLoginFailedAttempt(0);
440442
return $this->login_strategy->postLogin();
441443
}
442444

@@ -467,16 +469,15 @@ public function postLogin()
467469
}
468470

469471
$otpClaim = OAuth2OTP::fromParams($username, $connection, $password);
472+
470473
$this->auth_service->loginWithOTP($otpClaim, $client);
474+
$user?->setLoginFailedAttempt(0);
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 = $user?->updateLoginFailedAttempt() ?? 0;
480481

481482
return $this->login_strategy->errorLogin
482483
(
@@ -505,7 +506,7 @@ public function postLogin()
505506
'validator' => $validator,
506507
];
507508

508-
if (is_null($user) && isset($data['username'])) {
509+
if (is_null($user) && !empty($data['username'])) {
509510
$user = $this->auth_service->getUserByUsername($data['username']);
510511
}
511512

0 commit comments

Comments
 (0)