Checking Hashed Values

Submitted by chadwithuhc - 3 years ago

When you want to check a Hashed value generated by `Hash::make()` you need to use `Hash::check('unhashed', $hashed)`. Every time you run `Hash::make('string')`, a different hash is made and will not match the previous one.

// Generate a hash
$password = Hash::make('password');

// $password == $2y$08$T9r9qUxrr6ejs9Ne.nLzMet8l0A8BM5QvLjhaaJasgsbMBdX4JjRu

// Generate a new hash
$new_password = Hash::make('password');

// $new_password == $2y$08$3KBlYKIMpIvk.TWwim9oPuwGA.Pzv1iF7BsDyYkz7kQlhkA/ueULe

// Compare hashes the WRONG way
$password === $new_password; // false

// Compare hash the RIGHT way
Hash::check('password', $password); // true
Hash::check('password', $new_password); // true
comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks