Skip to content

Commit ca764ca

Browse files
committed
Added throttling to password reset requests
1 parent 543ea6e commit ca764ca

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

app/Config/auth.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
'email' => 'emails.password',
7171
'table' => 'password_resets',
7272
'expire' => 60,
73+
'throttle' => 60,
7374
],
7475
],
7576

app/Http/Controllers/Auth/ForgotPasswordController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function sendResetLinkEmail(Request $request)
5656
$this->logActivity(ActivityType::AUTH_PASSWORD_RESET, $request->get('email'));
5757
}
5858

59-
if ($response === Password::RESET_LINK_SENT || $response === Password::INVALID_USER) {
59+
if (in_array($response, [Password::RESET_LINK_SENT, Password::INVALID_USER, Password::RESET_THROTTLED])) {
6060
$message = trans('auth.reset_password_sent', ['email' => $request->get('email')]);
6161
$this->showSuccessNotification($message);
6262

tests/Auth/AuthTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,22 @@ public function test_reset_password_page_shows_sign_links()
282282
->assertElementContains('a', 'Sign up');
283283
}
284284

285+
public function test_reset_password_request_is_throttled()
286+
{
287+
$editor = $this->getEditor();
288+
Notification::fake();
289+
$this->get('/password/email');
290+
$this->followingRedirects()->post('/password/email', [
291+
'email' => $editor->email,
292+
]);
293+
294+
$resp = $this->followingRedirects()->post('/password/email', [
295+
'email' => $editor->email,
296+
]);
297+
Notification::assertTimesSent(1, ResetPassword::class);
298+
$resp->assertSee('A password reset link will be sent to ' . $editor->email . ' if that email address is found in the system.');
299+
}
300+
285301
public function test_login_redirects_to_initially_requested_url_correctly()
286302
{
287303
config()->set('app.url', 'http://localhost');

0 commit comments

Comments
 (0)