Skip to content

Commit

Permalink
Added throttling to password reset requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddanbrown committed Oct 8, 2021
1 parent 543ea6e commit ca764ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/Config/auth.php
Expand Up @@ -70,6 +70,7 @@
'email' => 'emails.password',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/ForgotPasswordController.php
Expand Up @@ -56,7 +56,7 @@ public function sendResetLinkEmail(Request $request)
$this->logActivity(ActivityType::AUTH_PASSWORD_RESET, $request->get('email'));
}

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

Expand Down
16 changes: 16 additions & 0 deletions tests/Auth/AuthTest.php
Expand Up @@ -282,6 +282,22 @@ public function test_reset_password_page_shows_sign_links()
->assertElementContains('a', 'Sign up');
}

public function test_reset_password_request_is_throttled()
{
$editor = $this->getEditor();
Notification::fake();
$this->get('/password/email');
$this->followingRedirects()->post('/password/email', [
'email' => $editor->email,
]);

$resp = $this->followingRedirects()->post('/password/email', [
'email' => $editor->email,
]);
Notification::assertTimesSent(1, ResetPassword::class);
$resp->assertSee('A password reset link will be sent to ' . $editor->email . ' if that email address is found in the system.');
}

public function test_login_redirects_to_initially_requested_url_correctly()
{
config()->set('app.url', 'http://localhost');
Expand Down

0 comments on commit ca764ca

Please sign in to comment.