Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare two encrypted(bcrypt) password in laravel

How to compare two bcrypt password

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

And

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

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

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

$hash1 = Hash::make('test');
$hash2 = Hash::make('test');

var_dump(Hash::check('test', $hash1) && Hash::check('test', $hash2));
like image 576
Jija Avatar asked Mar 01 '16 06:03

Jija


People also ask

How does laravel compare passwords?

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... }

How do I match my bcrypt password?

Check A User Entered Password const bcrypt = require("bcryptjs") const passwordEnteredByUser = "mypass123" const hash = "YOUR_HASH_STRING" bcrypt. compare(passwordEnteredByUser, hash, function(err, isMatch) { if (err) { throw err } else if (! isMatch) { console. log("Password doesn't match!") } else { console.

How does bcrypt compare with PHP password?

The PHP app handles the user registration and hashes the password using password_hash() . The password_hash() function uses the bcrypt algorithm if you specify PASSWORD_DEFAULT or PASSWORD_BCRYPT . With Node, the bcrypt NPM module can be used to compare the hash and the plain password, with a little gotcha.


1 Answers

if(Hash::check('plain-text-password',$cryptedpassword)) {
    // Right password
} else {
    // Wrong one
}
like image 62
Martin Avatar answered Sep 28 '22 18:09

Martin