Laravel Hash :: check()总是返回false

Dol*_*rma 15 php laravel laravel-4

我有个人资料表格供用户编辑自己的个人资料.在这种形式,我有当前的密码.必须匹配从seved到数据库.

形成:

{{ Form::password('currPassword', array('id'=>'currPassword')) }}
Run Code Online (Sandbox Code Playgroud)

我想在Controller中使用此功能来检查数据库.

$data = User::find($id);
if( ! Hash::check( $data->password , Input::get('currPassword') ) )
{
    return Redirect::to('/admin/profile')
        ->with('message', 'Current Password Error !')
        ->withInput();
}
Run Code Online (Sandbox Code Playgroud)

哈希123456密码进入数据库是确定的,并把后123456currPassword那一定是收益TRUE但回报FALSE始终.

Joe*_*inz 39

你使用了错误的参数顺序.这Hash::check($input, $hash),不是周围的其他方式.

短修补器示例:

[1] > $pw = 123456;
// 123456
[2] > $hashed = Hash::make($pw);
// '$2y$10$xSugoyKv765TY8DsERJ2/.mPIOwLNdM5Iw1n3x1XNVymBlHNG4cX6'
[3] > Hash::check($hashed, $pw);
// false
[4] > Hash::check($pw, $hashed);
// true
Run Code Online (Sandbox Code Playgroud)


Has*_*mal 6

Hash::check() 有两个参数,一个是平面密码,另一个是散列密码。如果密码与哈希匹配,它将返回 true。

Hash::check(normal_password,hashed_password);
Run Code Online (Sandbox Code Playgroud)

例子 :

Hash::check('123456a','$2y$10$.XB30GO4jn7bx7EauLrWkugIaCNGxiQCgrFTeFDeSSrGdQYd6Rneq');
Run Code Online (Sandbox Code Playgroud)


Ale*_*mov 5

我遇到了同样的问题并像这样解决了它:

我发现我在我的 RegistrationService 类中使用了 Hash::make 函数,更重要的是我已经在我的User 模型中使用了setPasswordAttribute函数,但很快就忘记了:

class User extends Model implements AuthenticatableContract, AuthorizableContract
{
   ...

    /**
     * @param $value
     */
    public function setPasswordAttribute($value)
    {
        $this->attributes['password'] = Hash::make($value);
    }
}
Run Code Online (Sandbox Code Playgroud)

所以密码是双重散列的,当然每个 Hash::check 调用都不正确并返回 false。

  • 太感谢了!我有一个生成超级管理员的 Seeder,它称为哈希,然后在用户管理模块上工作时,我做了和你一样的事情 (3认同)