Laravel 密码检查更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21508754/
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
Laravel password check for changing
提问by Robbo
In Laravel 4 I have the following condition to see if the user has inserted his current password correctly, and if yes, then do something.
在 Laravel 4 中,我有以下条件来查看用户是否正确插入了当前密码,如果是,则执行某些操作。
Here is the code:
这是代码:
if(Auth::user()->password==Hash::make(Input::get('old_password')) )
{
echo 'done';
}
But it does not meet the condition. Why?
但是不满足条件。为什么?
回答by Robbo
Because part of the hash is the salt which will never be the same. You need to use the Hash::check
method instead which knows what to do properly. So...
因为哈希的一部分是永远不会相同的盐。您需要使用Hash::check
知道如何正确执行的方法。所以...
if (Hash::check(Input::get('old_password'), Auth::user()->password)) {
echo 'done';
}
回答by Verron Knowles
Auth::validate is also an option if your end goal is to make sure the user is who he/she says they are.
如果您的最终目标是确保用户是他/她所说的那个人,那么 Auth::validate 也是一个选项。
$credentials = ['email' => Auth::user()->email, 'password' => Input::get('old_password')];
if (Auth::validate($credentials)) {
echo "Successful";
}