How to compare two encrypted passwords (bcrypt) in laravel

How to compare two bcrypt passwords

$pass1 = '$2y$10$ooPG9s1lcwUGYv1nqeyNcO0ccYJf8hlhm5dJXy7xoamvgiczXHB7S'; 

AND

 $pass2 = '$2y$10$QRgaiS6bpATKKQeT22zGKuHq.edDfXQc2.4B3v.zaN.GtGwoyQuMy'; 

Both $ pass1 and $ pass2 are bcrypt for 'test'.

How can I check equality. without using textual 'test' like this

 $hash1 = Hash::make('test'); $hash2 = Hash::make('test'); var_dump(Hash::check('test', $hash1) && Hash::check('test', $hash2)); 
+5
source share
3 answers

You cannot actually compare the two encrypted bcrypt passwords with each other directly as strings, because the encryption contains salt, which makes the hashes different.

+3
source
 if(Hash::check('plain-text-password',$cryptedpassword)) { // Right password } else { // Wrong one } 
+11
source

You can simply use the Hash::check() method for example:

 if(Hash::check('plain-text', $hashedPassword)) { return true; } 

link https://laravel.com/docs/5.5/hashing

0
source

Source: https://habr.com/ru/post/1244179/


All Articles