Skip to content

Commit

Permalink
[1.x] Support case insensitive password resets (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmcdonald-uk authored Aug 9, 2024
1 parent 9b36dfc commit 958042c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Http/Controllers/PasswordResetLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Str;
use Laravel\Fortify\Contracts\FailedPasswordResetLinkRequestResponse;
use Laravel\Fortify\Contracts\RequestPasswordResetLinkViewResponse;
use Laravel\Fortify\Contracts\SuccessfulPasswordResetLinkRequestResponse;
Expand Down Expand Up @@ -35,6 +36,12 @@ public function store(Request $request): Responsable
{
$request->validate([Fortify::email() => 'required|email']);

if (config('fortify.lowercase_usernames')) {
$request->merge([
Fortify::email() => Str::lower($request->{Fortify::email()}),
]);
}

// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
Expand Down
16 changes: 16 additions & 0 deletions tests/PasswordResetLinkRequestControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,20 @@ public function test_reset_link_can_be_successfully_requested_with_customized_em
$response->assertSessionHasNoErrors();
$response->assertSessionHas('status', trans(Password::RESET_LINK_SENT));
}

public function test_case_insensitive_usernames_can_be_used()
{
Config::set('fortify.lowercase_usernames', true);
Password::shouldReceive('broker')->andReturn($broker = Mockery::mock(PasswordBroker::class));

$broker->shouldReceive('sendResetLink')->andReturn(Password::RESET_LINK_SENT);

$response = $this->from(url('/forgot-password'))
->post('/forgot-password', ['email' => 'TAYLOR@laravel.com']);

$response->assertStatus(302);
$response->assertRedirect('/forgot-password');
$response->assertSessionHasNoErrors();
$response->assertSessionHas('status', trans(Password::RESET_LINK_SENT));
}
}

0 comments on commit 958042c

Please sign in to comment.