Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bohowe's avatar

uppercase lowercase login

I am allowing users to register and then login using username / password. If I login user with uppercase and lowercase username it always login. At register it seems I can use uppercase and lowercase

Is this how its supposed to be?

0 likes
3 replies
tykus's avatar

Most likely your database is case-insensitive., e.g. MySQL queries are not case-sensitive by default.

If you must have a case-sensitive search, you have the choice to either (i) define the username column to be case-sensitive, or (ii) force the query to be case sensitive.

bobbybouwmann's avatar
Level 88

Yes, this is the correct and default behavior of Laravel's authentication system.

However, you can change this behavior if you wish. Assuming that you're using the default LoginController, you can override the credentials method in the App\Http\Controllers\Auth\LoginController.

protected function credentials(Request $request)
{
    $credentials = [
        $this->username() => strtolower($request->input($this->username())),
        'password' => $request->get('password'),
    ];
    
    return $credentials;
}

After that you need to make sure all emails are stored in lowercase in your database. You can add the following method to your User model to achieve that

public function setEmailAttribute($value)
{
    $this->attributes['email'] = strtolower($value);
}

Let me know if that works for you!

Please or to participate in this conversation.