66use Illuminate \Auth \Events \Lockout ;
77use Illuminate \Foundation \Http \FormRequest ;
88use Illuminate \Support \Facades \Auth ;
9- use Illuminate \Support \Facades \Hash ;
109use Illuminate \Support \Facades \RateLimiter ;
1110use Illuminate \Support \Str ;
1211use Illuminate \Validation \ValidationException ;
13- use Laravel \Fortify \Features ;
1412
1513class LoginRequest extends FormRequest
1614{
@@ -36,34 +34,18 @@ public function rules(): array
3634 }
3735
3836 /**
39- * Attempt to authenticate the request's credentials.
37+ * Validate the request's credentials and return the user without logging them in .
4038 *
4139 * @throws \Illuminate\Validation\ValidationException
4240 */
43- public function authenticate ()
41+ public function validateCredentials (): User
4442 {
4543 $ this ->ensureIsNotRateLimited ();
4644
47- // Check if two-factor authentication is enabled
48- if (Features::enabled (Features::twoFactorAuthentication ())) {
49- $ user = User::where ('email ' , $ this ->email )->first ();
45+ /** @var User $user */
46+ $ user = Auth::getProvider ()->retrieveByCredentials ($ this ->only ('email ' , 'password ' ));
5047
51- // If this user exists, the password is correct, and 2FA is enabled; we want to redirect to the 2FA challenge
52- if ($ user && $ user ->two_factor_confirmed_at && Hash::check ($ this ->password , $ user ->password )) {
53- // Store the user ID and remember preference in the session
54- $ this ->session ()->put ([
55- 'login.id ' => $ user ->getKey (),
56- 'login.remember ' => $ this ->boolean ('remember ' ),
57- ]);
58-
59- RateLimiter::clear ($ this ->throttleKey ());
60-
61- return redirect ()->route ('two-factor.login ' );
62- }
63- }
64-
65- // Proceed with normal authentication if 2FA is not enabled or the user doesn't have 2FA
66- if (! Auth::attempt ($ this ->only ('email ' , 'password ' ), $ this ->boolean ('remember ' ))) {
48+ if (! $ user || ! Auth::getProvider ()->validateCredentials ($ user , $ this ->only ('password ' ))) {
6749 RateLimiter::hit ($ this ->throttleKey ());
6850
6951 throw ValidationException::withMessages ([
@@ -72,6 +54,8 @@ public function authenticate()
7254 }
7355
7456 RateLimiter::clear ($ this ->throttleKey ());
57+
58+ return $ user ;
7559 }
7660
7761 /**
0 commit comments