Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ public function postLogin()
{
$max_login_attempts_2_show_captcha = $this->server_configuration_service->getConfigValue("MaxFailed.LoginAttempts.2ShowCaptcha");
$max_login_failed_attempts = intval($this->server_configuration_service->getConfigValue("MaxFailed.Login.Attempts"));
$login_attempts = 0;
$username = '';
$login_attempts = (int) Session::get('captcha_failed_attempts', 0);
$username = '';
$user = null;

try
Expand All @@ -411,7 +411,6 @@ public function postLogin()
if (isset($data['password']))
$data['password'] = trim($data['password']);

$login_attempts = intval(Request::input('login_attempts'));
// Build the validation constraint set.
$rules = [
'username' => 'required|email',
Expand All @@ -436,7 +435,10 @@ public function postLogin()
$connection = $data['connection'] ?? null;

try {
$user = $this->auth_service->getUserByUsername($username);
if ($flow == "password" && $this->auth_service->login($username, $password, $remember)) {
Session::forget('captcha_failed_attempts');
Session::save();
return $this->login_strategy->postLogin();
}

Expand Down Expand Up @@ -468,15 +470,18 @@ public function postLogin()

$otpClaim = OAuth2OTP::fromParams($username, $connection, $password);
$this->auth_service->loginWithOTP($otpClaim, $client);
Session::forget('captcha_failed_attempts');
Session::save();
return $this->login_strategy->postLogin();
}
} catch (AuthenticationException $ex) {
// failed login attempt...

$user = $this->auth_service->getUserByUsername($username);
if (!is_null($user)) {
$login_attempts = $user->getLoginFailedAttempt();
}
$login_attempts = $login_attempts + 1;
Session::put('captcha_failed_attempts', $login_attempts);
Session::save();

// User.loginFailedAttempt drives account lockout (persisted by auth_service).

return $this->login_strategy->errorLogin
(
Expand Down Expand Up @@ -525,6 +530,9 @@ public function postLogin()
Log::warning($ex1);

$user = $this->auth_service->getUserByUsername($username);
$login_attempts = $login_attempts + 1;
Session::put('captcha_failed_attempts', $login_attempts);
Session::save();

$response_data = [
'max_login_attempts_2_show_captcha' => $max_login_attempts_2_show_captcha,
Expand Down
2 changes: 0 additions & 2 deletions resources/js/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ const PasswordInputForm = ({
<input type="hidden" value={userNameValue} id="username" name="username"/>
<input type="hidden" value={csrfToken} id="_token" name="_token"/>
<input type="hidden" value="password" id="flow" name="flow"/>
<input type="hidden" value={loginAttempts} id="login_attempts" name="login_attempts"/>
{shouldShowCaptcha() && captchaPublicKey &&
<Turnstile
className={styles.turnstile}
Expand Down Expand Up @@ -271,7 +270,6 @@ const OTPInputForm = ({
<input type="hidden" value="otp" id="flow" name="flow"/>
<input type="hidden" value={otpCode} id="password" name="password"/>
<input type="hidden" value="email" id="connection" name="connection"/>
<input type="hidden" value={loginAttempts} id="login_attempts" name="login_attempts"/>
{shouldShowCaptcha() && captchaPublicKey &&
<Turnstile
className={styles.turnstile}
Expand Down
4 changes: 2 additions & 2 deletions resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
config.maxLoginFailedAttempts = {{Session::get("max_login_failed_attempts")}};
@endif

@if(Session::has('login_attempts'))
config.loginAttempts = {{Session::get("login_attempts")}};
@if(Session::has('captcha_failed_attempts'))
config.loginAttempts = {{Session::get("captcha_failed_attempts")}};
@endif

@if(Session::has('user_is_active'))
Expand Down
Loading
Loading