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

lifesound's avatar

Laravel 9 invalid cred

I have an old Laravel 9 project that now gives invalid credentials suddenly the user is in the db I see it

I did not change anything

seeder

what could be wrong

the password hash does not match

I am using username instead of email

I tested it in tinker

and it resulted true!!

php artisan tinker

Psy Shell v0.11.10 (PHP 8.2.22 — cli) by Justin Hileman
> $user = App\Models\User::where('username', 'admin')->first();
= App\Models\User {#4091
    id: 1,
    created_by: null,
    name: "Mr Fantastic",
    username: "admin",
    #password: "$2y$10********************************",
    #remember_token: "********",
    created_at: "2024-08-28 20:15:09",
    updated_at: "2024-08-28 20:15:09",

  }

> Hash::check('e********', $user->password);
= false

where if I did

>
> Hash::check(env('USER_PASS'), $user->password);

   DEPRECATED  password_verify(): Passing null to parameter #1 ($password) of type string is deprecated in vendor/laravel/framework/src/Illuminate/Hashing/AbstractHasher.php on line 32.

= true

Laravel authenticate func

 public function authenticate()
    {
        $this->ensureIsNotRateLimited();

        if (! Auth::attempt($this->only('username', 'password'), $this->boolean('remember'))) {
            RateLimiter::hit($this->throttleKey());

            throw ValidationException::withMessages([
                'username' => trans('auth.failed'),
            ]);
        }

        RateLimiter::clear($this->throttleKey());
    }

I also cleared all caches

php artisan --version
Laravel Framework 9.46.0
0 likes
11 replies
tykus's avatar

Are you double hashing the password?

1 like
lifesound's avatar

@tykus how? where? I did not not change anything May I did some mistake which I do not think so but tell me where to check.

lifesound's avatar

@tykus i have did some updates and composer autoload to remove the error above

> Hash::check('e********', $user->password);
= false

now there is no errors but the hashing logic seems has some issue

lifesound's avatar

@tykus where if I did


> Hash::check(env('USER_PASS'), $user->password);

   DEPRECATED  password_verify(): Passing null to parameter #1 ($password) of type string is deprecated in vendor/laravel/framework/src/Illuminate/Hashing/AbstractHasher.php on line 32.

= true <=============|||||||||||||||||||||||||=====

So it is true if coming from env while not from plain text from browser request !!

lifesound's avatar

@tykus Now i see the password is null so env func not working properly

> Hash::check(null, $user->password);

   DEPRECATED  password_verify(): Passing null to parameter #1 ($password) of type string is deprecated in vendor/laravel/framework/src/Illuminate/Hashing/AbstractHasher.php on line 32.

= true
JussiMannisto's avatar

You're passing Hash::make(env('USER_PASS')) as the user's password in the seeder. If the user model has automatic hashing via casting, then that password gets hashed twice. This is what @tykus was talking about.

Check if you user model has something like this:

protected $casts = [
	...
	'password' => 'hashed',
	...
];

// Or:
protected function casts(): array {
	return [		
		...
		'password' => 'hashed',
		...
	];
}

If it does, you don't need to hash the password beforehand.

1 like
lifesound's avatar

@JussiMannisto I do not have these 'password' => 'hashed', i removed the env func and add the password hard coded and it works

lifesound's avatar

@JussiMannisto I have it it is in front of me in .env file

I have another env file called env.example but I do not think it is related to do anything

JussiMannisto's avatar
Level 50

@lifesound Well it's null when you're trying to access it with env('USER_PASS'). The error message you posted shows this:

> Hash::check(env('USER_PASS'), $user->password);

   DEPRECATED  password_verify(): Passing null to parameter #1 ($password) of type string is deprecated in (...)
1 like
lifesound's avatar

@JussiMannisto yes there is something weird

although it connects to db from this .env file and it works for these env variables

1 like

Please or to participate in this conversation.