Skip to content

Allow login and registration with capitalized emails #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/views/livewire/auth/forgot-password.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function sendPasswordResetLink(): void
$this->validate([
'email' => ['required', 'string', 'email'],
]);

$this->email = mb_strtolower($this->email);
Password::sendResetLink($this->only('email'));

session()->flash('status', __('A reset link will be sent if the account exists.'));
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function login(): void

$this->ensureIsNotRateLimited();

if (! Auth::attempt(['email' => $this->email, 'password' => $this->password], $this->remember)) {
if (! Auth::attempt(['email' => mb_strtolower($this->email), 'password' => $this->password], $this->remember)) {
RateLimiter::hit($this->throttleKey());

throw ValidationException::withMessages([
Expand Down
3 changes: 2 additions & 1 deletion resources/views/livewire/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public function register(): void
{
$validated = $this->validate([
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . User::class],
'email' => ['required', 'string', 'email', 'max:255', 'unique:' . User::class],
'password' => ['required', 'string', 'confirmed', Rules\Password::defaults()],
]);

$validated['email'] = mb_strtolower($validated['email']);
$validated['password'] = Hash::make($validated['password']);

event(new Registered(($user = User::create($validated))));
Expand Down
7 changes: 4 additions & 3 deletions resources/views/livewire/auth/reset-password.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,26 @@ public function mount(string $token): void
{
$this->token = $token;

$this->email = request()->string('email');
$this->email = mb_strtolower(request()->string('email'));
}

/**
* Reset the password for the given user.
*/
public function resetPassword(): void
{
$this->validate([
$validated = $this->validate([
'token' => ['required'],
'email' => ['required', 'string', 'email'],
'password' => ['required', 'string', 'confirmed', Rules\Password::defaults()],
]);
$validated['email'] = mb_strtolower($validated['email']);

// Here we will attempt to reset the user's password. If it is successful we
// will update the password on an actual user model and persist it to the
// database. Otherwise we will parse the error and return the response.
$status = Password::reset(
$this->only('email', 'password', 'password_confirmation', 'token'),
$this->only($validated['email'], 'password', 'password_confirmation', 'token'),
Copy link
Contributor

@Rattone Rattone Apr 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only() method accept input names not values

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Rattone, yes, @cspohn-ltb, can you make this update.

function ($user) {
$user->forceFill([
'password' => Hash::make($this->password),
Expand Down