Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel login throws a RuntimeException about the Bcrypt algorithm

ErrorThis password does not use the Bcrypt algorithm.

Short answer

Hash::check first confirms that the stored hash was made with the hashing algorithm your app is set to use. If it was not, Laravel throws a RuntimeException instead of returning false. Either the stored value is not a Laravel hash at all, or HASH_DRIVER names a different algorithm than the one that made it. Match the driver to the data, or migrate with HASH_VERIFY temporarily off.

  • Applies to Laravel 11, Laravel 12, PHP 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the stored value for one failing user and compare it with the driver the app uses. The two have to be the same algorithm.

    // in php artisan tinker
    echo App\Models\User::first()->password;
    echo config('hashing.driver');
  2. 2Match what you see, then jump to its fix

    1. 1The password column holds plain text or a hash from some other systemThe stored password was never hashed by LaravelFix
    2. 2HASH_DRIVER (or config/hashing.php) names an algorithm other than the one that made the stored hashes, for example after switching between bcrypt, argon and argon2idThe hashes were made by another Laravel driver than the one configuredFix

What does the error look like?

  • This password does not use the Bcrypt algorithm.
  • RuntimeException thrown from Hash::check during login

Cause 1 of 2

The stored password was never hashed by Laravel

1Check

Rows written by a raw INSERT, a careless seeder or an import from another application keep the format they arrived in.

// in php artisan tinker
echo App\Models\User::first()->password;

2Fix

Write the password again through Hash::make. If you do not know the plain-text password, send the user through a password reset instead.

use Illuminate\Support\Facades\Hash;

$user->password = Hash::make($plainPassword);
$user->save();

3Verify

Log in as that user.

// in php artisan tinker
Hash::check($plainPassword, $user->fresh()->password);

Confirmed by laravel.com

Did this fix it?

Cause 2 of 2

The hashes were made by another Laravel driver than the one configured

1Check

By default Laravel uses the bcrypt driver. The driver comes from the HASH_DRIVER environment variable or the hashing config file, and a stale cached config can hide a change.

grep -n "HASH_DRIVER" .env
php artisan config:clear

2Fix

Set HASH_DRIVER to the algorithm your stored hashes use. If you are moving users from one algorithm to another and both kinds exist for a while, set HASH_VERIFY=false so Hash::check stops testing the algorithm. Turn it back on after every hash has been replaced.

# .env
HASH_DRIVER=bcrypt

# only while two algorithms coexist
HASH_VERIFY=false

3Verify

Clear the config cache and log in with a known account.

php artisan config:clear

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Create and update passwords only through Hash::make, never with a raw value in an INSERT or seeder.
  • When importing users from another system, plan the hash migration first and remove HASH_VERIFY=false once every hash is converted.
  • Set HASH_DRIVER in .env.example so every environment uses the same algorithm.
  • Use Hash::needsRehash after a successful login so a changed work factor rolls out by itself.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.