Im new to Laravel. Im trying to set a counter of failed login attempts by using sessions. However I not able to make it work. Here is my UserController handling registration, login and logout. I wanna have a global variable, which I can access from the login form and force user to use CAPTCHA if there is more than 2 failed logins
public function postSignIn(Request $request)
{
$failedAttempt = Session::get('FailedAttempts');
if(!isset($failedAttempt)) $failedAttempt = 0;
$this->validate($request, [
'email' => 'required',
'password' => 'required'
]);
if (Auth::attempt(['email' => $request['email'], 'password' =>
$request['password'], 'active' => 1])) {
return redirect()->route('dashboard');
} else {
$failedAttempt++;
Session::put('FailedAttempts', $failedAttempt);
dd("Counter: " . $failedAttempt); //<- Always 1!!!
}
$failedAttempt never gets incremented on the next failed login attempts. I've tried Session::set('FailedAttempts', $failedAttempt);, session(['FailedAttempts' => $failedAttempt]); but still no luck
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire