Skip to content

Commit 5955b14

Browse files
committed
Fix authentication handler
Check email & password before token to handle case where email is invalid.
1 parent 9c9d33c commit 5955b14

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

app/Http/Controllers/Auth/AuthController.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,31 @@ public function postLogin(Request $request)
115115
return $this->sendLockoutResponse($request);
116116
}
117117

118+
// Is the email & password valid?
119+
if (!Auth::attempt([
120+
'email' => $request->input('email'),
121+
'password' => $request->input('password')
122+
], $request->has('remember'))) {
123+
124+
if ($throttled) {
125+
$this->incrementLoginAttempts($request);
126+
}
127+
128+
return redirect()->route('auth.login')->withInput($request->only('email', 'remember'))->withErrors([
129+
'email' => $this->getFailedLoginMessage(),
130+
]);
131+
132+
}
133+
118134
$G2FA = new Google2FA();
119-
$user = User::select('use_totp', 'totp_secret')->where('email', $request->input($this->loginUsername()))->first();
135+
$user = User::select('use_totp', 'totp_secret')->where('email', $request->input('email'))->first();
120136

121137
// Verify TOTP Token was Valid
122138
if($user->use_totp === 1) {
123139
if(!$G2FA->verifyKey($user->totp_secret, $request->input('totp_token'))) {
124140

141+
Auth::logout();
142+
125143
if ($throttled) {
126144
$this->incrementLoginAttempts($request);
127145
}
@@ -132,23 +150,8 @@ public function postLogin(Request $request)
132150
}
133151
}
134152

135-
// Attempt to Login
136-
if (Auth::attempt([
137-
'email' => $request->input('email'),
138-
'password' => $request->input('password')
139-
], $request->has('remember'))) {
140-
return $this->handleUserWasAuthenticated($request, $throttled);
141-
}
142-
143-
if ($throttled) {
144-
$this->incrementLoginAttempts($request);
145-
}
153+
return $this->handleUserWasAuthenticated($request, $throttled);
146154

147-
return redirect()->route('auth.login')
148-
->withInput($request->only('email', 'remember'))
149-
->withErrors([
150-
'email' => $this->getFailedLoginMessage(),
151-
]);
152155
}
153156

154157
/**

0 commit comments

Comments
 (0)