validate(); $this->ensureIsNotRateLimited(); $user = $this->validateCredentials(); if (Features::canManageTwoFactorAuthentication() && $user->hasEnabledTwoFactorAuthentication()) { Session::put([ 'login.id' => $user->getKey(), 'login.remember' => $this->remember, ]); $this->redirect(route('two-factor.login'), navigate: true); return; } Auth::login($user, $this->remember); RateLimiter::clear($this->throttleKey()); Session::regenerate(); $this->redirectIntended(default: route('dashboard', absolute: false), navigate: true); } /** * Validate the user's credentials. */ protected function validateCredentials(): User { $user = Auth::getProvider()->retrieveByCredentials(['email' => $this->email, 'password' => $this->password]); if (! $user || ! Auth::getProvider()->validateCredentials($user, ['password' => $this->password])) { RateLimiter::hit($this->throttleKey()); throw ValidationException::withMessages([ 'email' => __('auth.failed'), ]); } return $user; } /** * Ensure the authentication request is not rate limited. */ protected function ensureIsNotRateLimited(): void { if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { return; } event(new Lockout(request())); $seconds = RateLimiter::availableIn($this->throttleKey()); throw ValidationException::withMessages([ 'email' => __('auth.throttle', [ 'seconds' => $seconds, 'minutes' => ceil($seconds / 60), ]), ]); } /** * Get the authentication rate limiting throttle key. */ protected function throttleKey(): string { return Str::transliterate(Str::lower($this->email).'|'.request()->ip()); } }