php 如何比较laravel中的两个加密(bcrypt)密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35715755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to compare two encrypted(bcrypt) password in laravel
提问by Jija
How to compare two bcrypt password
如何比较两个bcrypt密码
$pass1 = 'y$ooPG9s1lcwUGYv1nqeyNcO0ccYJf8hlhm5dJXy7xoamvgiczXHB7S';
And
和
$pass2 = 'y$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));
采纳答案by Joseph
You can't actually compare two encrypted bcrypt passwords to each other directly as strings because the encryption contains salt which makes the hashes different each time.
您实际上无法将两个加密的 bcrypt 密码直接作为字符串相互比较,因为加密包含使哈希值每次都不同的盐。
回答by Martin
if(Hash::check('plain-text-password',$cryptedpassword)) {
// Right password
} else {
// Wrong one
}
回答by Rahul Reghunath
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
回答by bharat
You can try this way:
你可以试试这个方法:
if (Hash::check('test', bcrypt('test'))) {
return 'match!!';
}else{
return 'not match!!';
}
回答by pankaj kumar
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'))