[英]How to compare two encrypted(bcrypt) password in laravel
How to compare two bcrypt password如何比较两个bcrypt密码
$pass1 = '$2y$10$ooPG9s1lcwUGYv1nqeyNcO0ccYJf8hlhm5dJXy7xoamvgiczXHB7S';
And和
$pass2 = '$2y$10$QRgaiS6bpATKKQeT22zGKuHq.edDfXQc2.4B3v.zaN.GtGwoyQuMy';
Both $pass1 & $pass2 are bcrypt for 'test'. $pass1 和 $pass2 都是 'test' 的 bcrypt。
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));
if(Hash::check('plain-text-password',$cryptedpassword)) {
// Right password
} else {
// Wrong one
}
You can simply use Hash::check()
method eg:您可以简单地使用Hash::check()
方法,例如:
if(Hash::check('plain-text', $hashedPassword)) {
return true;
}
reference https://laravel.com/docs/5.5/hashing参考https://laravel.com/docs/5.5/hashing
您实际上无法将两个加密的 bcrypt 密码直接作为字符串相互比较,因为加密包含使哈希值每次都不同的盐。
You can try this way:你可以试试这个方法:
if (Hash::check('test', bcrypt('test'))) {
return 'match!!';
}else{
return 'not match!!';
}
you can compare hash encrypt the password using Hash
.您可以使用Hash
比较哈希加密密码。
but note that in this method the first value should be plain-text
and second bcrypt
value.但请注意,在此方法中,第一个值应该是plain-text
,第二个是bcrypt
值。
Hash::check('test', bcrypt('test'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.