3

I am storing my Password as BCrypt (Laravel own way)

$NewValue = Hash::make(Input::get('Password'));

$OldValue = Auth::user()->password;  // Taking the value from database
if($NewValue == $OldValue)
{
return 'Both Password are equal'
}
else
{
//go for other operation
}

But whenever i check the if condition, I am always getting false.

What is the mistake i am doing ?

AngularAngularAngular
  • 3,589
  • 5
  • 25
  • 41

2 Answers2

5

Laravel's hash function will generate a new hash every time you call Hash::make. Internally it calls password_hash which then uses crypt. It will always generate a random salt. The salt is included in the final hash so when comparing it can be parsed and used to generate the same hash again.

To verify a password you need to use Hash::check() which then uses password_verify under the hood

$password = Input::get('Password');
$hashedPassword = Auth::user()->password;  // Taking the value from database

if(Hash::check($password, $hashedPassword))
{
    return 'Both Password are equal'
}
else
{
    //go for other operation
}
lukasgeiter
  • 147,337
  • 26
  • 332
  • 270
1

Use Hash::check() to verify a password against a hash.

Hash::check('secret', $hashedPassword);

Docs - Security - Storing passwords

lagbox
  • 48,571
  • 8
  • 72
  • 83