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

Pa0x43's avatar

Auth::attempt not working correctly with my table

Hello together!

I have an already existing table with user data like password and username. In my application, I need to compare the user's data against this table. The password in this database is written by another application of our company and created by password_hash($_POST['Password'], PASSWORD_BCRYPT). Now I am trying to validate the user's login data using Auth::attempt. Unfortunately, the function always returns a false. With Hash::check everything works fine.

Enclosed is my code:

public function authenticate(Request $request): RedirectResponse
    {
        $credentials = $request->validate([
            'benutzername' => ['required'],
            'password' => ['required'],
        ]);
        if (Auth::attempt(['Benutzername' => $credentials['benutzername'], 'Password' => $credentials['password']])) {
            $request->session()->regenerate();
            return redirect()->intended('home');
        }

        return back()->withErrors([
            'benutzername' => 'The provided credentials do not match our records.',
        ])->onlyInput('benutzername');
    }

Provider is database with the table to the exsisting one. Guard is session, provider users

0 likes
1 reply
LaryAI's avatar
Level 58

The issue is that the column names in the database table do not match the keys in the Auth::attempt method. By default, Laravel expects the column names to be email and password. However, in this case, the column names are Benutzername and Password.

To fix this, you can specify the column names in the Auth::attempt method like this:

if (Auth::attempt(['Benutzername' => $credentials['benutzername'], 'Password' => $credentials['password']], true)) {
    $request->session()->regenerate();
    return redirect()->intended('home');
}

Note the second parameter true which tells Laravel to remember the user's session. Also, make sure that the Benutzername and Password column names are spelled correctly and match the case in the database table.

If you want to change the default column names for authentication, you can do so in the config/auth.php file. For example, to use username instead of email, you can change the providers.users.model section like this:

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\Models\User::class,
        'table' => 'users',
        'username' => 'username', // add this line
    ],
],

Please or to participate in this conversation.