Hash :: check()在Laravel中返回false

时间:2017-02-04 07:28:10

标签: laravel laravel-5

我使用Hash :: check()次数进行密码更新功能。它工作正常。但在这里它总是返回false。我不明白为什么它返回假。这是适合我的代码。

$pass_data = array(
            'current_pass' => $post['old_pass'],
            'new_pass' => $post['new_pass'],
            );
$pass_data['new_pass'] = bcrypt($pass_data['new_pass']);

    if (\Hash::check($pass_data['current_pass'],\Auth::user()->password )) 
            {

            $user = new User();
             if($user->where('id',\Auth::user()->id)->update(['password'=>$pass_data['new_pass']])){
                    return response()->json(['msg'=>'Password Changed']);
                }
            }

             else{
                return response()->json(['msg'=>'Wrong Password']);
            }

这是返回false的代码,这里$ mem_id不是Authenticated用户(是因为更改了非经过身份验证的用户的pass?)。

    $mem_id = $request['mem_id'];
    $old_pass = $request['mem_old_pass'];
    $mem_pass = User::where('id',$mem_id)->pluck('password');


    if (\Hash::check($old_pass,$mem_pass )) {

        $new_pass = bcrypt($request['mem_new_pass']);

        $update = User::where('id',$mem_id)->update(['name'=>$request['mem_name'],'email'=>$request['mem_email'],'password'=>$new_pass]);


        if ($update) {

            $updated_user = User::where('id',$mem_id)->get();
            return response()->json(['msg'=>'updated','user'=>$updated_user]);
        }
        else{

            return response()->json(['msg'=>'update_failed']);
        }
    }

    else{
        return response()->json(['msg'=>'pass_fail']);
    } 

我收到回复'pass_fail'

3 个答案:

答案 0 :(得分:1)

因为pluck方法没有返回指定的列值。

答案 1 :(得分:0)

http://www.abc.xyz/webservices/facade

if (Hash::check('plain-text', $hashedPassword)) {
    // The passwords match...
}

您传递的Hash::check不是纯文字密码,而是bcrypt($old_pass);的结果。你应该传递纯文本,而不是加密。

答案 2 :(得分:0)

问题在于pluck()。当我使用这段代码时,它工作得很好

<form name="myForm">
    <div class="col-sm-4">
      <input class="form-control"
        type="text"
        data-ng-model="model_name"
        name="modelName"
        ng-pattern="/^[\/,.]/" required> 
      <div ng-messages="myForm.$submitted && myForm.modelName.$error" role="alert">
        <div class="alert alert-danger" ng-message="pattern">Special characters [/ , .] are not allowed.</div>
        <div class="alert alert-danger" ng-message="required">This field is required.</div>
      </div>
    </div>
</form>

现在我将$ mem_pass传递给Hash :: check,它完美地运行了