How to compare a string password with laravel Encrypted Password

2 ways:

1.

$hashedPassword = User::find(1)->password;

if (Hash::check('plain-text-password', $hashedPassword)) {
    // The passwords match...
}
$hashedPassword = User::find(1)->password;

if (Hash::make('plain-text-password') === $hashedPassword) {
  // The passwords match...
}

However, as the official documentation says, and as a pro-DRY (Don't Repeat Yourself) approach, if you are using the LoginController included with Laravel, you will probably not need to use these 2 ways directly, as it automatically does the first way already.

Ref: https://laravel.com/docs/5.4/hashing

IMPORTANT UPDATE

The second way posted here does not work because Laravel uses bcrypt, which generates random a salt on each hash; making each hash different from the original hashed password in the the database. Use the first way instead. You may also read Where are laravel password salts stored?.


Hash::check is the best method to do it.

if(Hash::check('plain password', 'encrypted password')){
    //enter your code
}