Skip to content

Commit f78aef4

Browse files
committed
Ratelimiter messaging
1 parent 6bac8ac commit f78aef4

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

app/Http/Controllers/Account/AuthController.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Http\Controllers\Controller;
66
use App\Http\Requests\LoginRequest;
77
use Illuminate\Http\Request;
8+
use Illuminate\Support\Carbon;
89

910
class AuthController extends Controller
1011
{
@@ -21,17 +22,31 @@ public function logout()
2122
return redirect()->route('account.login');
2223
}
2324

25+
/**
26+
* Process the login request.
27+
*
28+
* @TODO Implement additional brute-force protection with custom blocked IPs model.
29+
*
30+
* @param LoginRequest $request
31+
* @throws \Illuminate\Validation\ValidationException
32+
* @return \Illuminate\Http\RedirectResponse
33+
*/
2434
public function processLogin(LoginRequest $request)
2535
{
2636
$credentials = $request->only('email', 'password');
2737
$key = 'login-attempt:' . $request->ip();
2838
$attemptsPerHour = 5;
2939

3040
if (\RateLimiter::tooManyAttempts($key, $attemptsPerHour)) {
41+
$blockedUntil = Carbon::now()
42+
->addSeconds(\RateLimiter::availableIn($key))
43+
->diffInMinutes(Carbon::now());
44+
3145
return back()
32-
->withInput($request->only('email'))
46+
->withInput($request->only(['email', 'remember']))
3347
->withErrors([
34-
'email' => 'Too many login attempts. Please try again later.',
48+
'email' => 'Too many login attempts. Please try again in '
49+
. $blockedUntil . ' minutes.',
3550
]);
3651
}
3752

0 commit comments

Comments
 (0)