Skip to content

Commit 958042c

Browse files
authored
[1.x] Support case insensitive password resets (#562)
1 parent 9b36dfc commit 958042c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Http/Controllers/PasswordResetLinkController.php

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Http\Request;
88
use Illuminate\Routing\Controller;
99
use Illuminate\Support\Facades\Password;
10+
use Illuminate\Support\Str;
1011
use Laravel\Fortify\Contracts\FailedPasswordResetLinkRequestResponse;
1112
use Laravel\Fortify\Contracts\RequestPasswordResetLinkViewResponse;
1213
use Laravel\Fortify\Contracts\SuccessfulPasswordResetLinkRequestResponse;
@@ -35,6 +36,12 @@ public function store(Request $request): Responsable
3536
{
3637
$request->validate([Fortify::email() => 'required|email']);
3738

39+
if (config('fortify.lowercase_usernames')) {
40+
$request->merge([
41+
Fortify::email() => Str::lower($request->{Fortify::email()}),
42+
]);
43+
}
44+
3845
// We will send the password reset link to this user. Once we have attempted
3946
// to send the link, we will examine the response then see the message we
4047
// need to show to the user. Finally, we'll send out a proper response.

tests/PasswordResetLinkRequestControllerTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,20 @@ public function test_reset_link_can_be_successfully_requested_with_customized_em
7979
$response->assertSessionHasNoErrors();
8080
$response->assertSessionHas('status', trans(Password::RESET_LINK_SENT));
8181
}
82+
83+
public function test_case_insensitive_usernames_can_be_used()
84+
{
85+
Config::set('fortify.lowercase_usernames', true);
86+
Password::shouldReceive('broker')->andReturn($broker = Mockery::mock(PasswordBroker::class));
87+
88+
$broker->shouldReceive('sendResetLink')->andReturn(Password::RESET_LINK_SENT);
89+
90+
$response = $this->from(url('/forgot-password'))
91+
->post('/forgot-password', ['email' => '[email protected]']);
92+
93+
$response->assertStatus(302);
94+
$response->assertRedirect('/forgot-password');
95+
$response->assertSessionHasNoErrors();
96+
$response->assertSessionHas('status', trans(Password::RESET_LINK_SENT));
97+
}
8298
}

0 commit comments

Comments
 (0)