Compare Plain String to Hash

LaravelPosted on

Sometimes we need to check if the user typed the correct password, even if the user is authenticated. For example, before changing its settings, we force the user to type the password again to increase the security of our application.

Laravel provides an Illuminate\Support\Facades\Hash facade, which helps us to word with hashing and encryption. If you are interested in its documentation you can find it here:

Note, since PHP 7.2 you can use the Argon2i hash driver.

So, to compare plain string with its hashed version, the facade offers the check method to perform this action.

use Illuminate\Support\Facades\Hash;

$user = App\User::first();

// Compare the string to the hash
Hash::check('password', $user->password);

Need a web developer? Maybe we can help, get in touch!

Similar Posts

More content in Laravel category