laravel修改密码及与原密码Hash::check比较

/**
 * 重置密码方法
 * @param Request $request
 */
public function set_password(Request $request){
    $id = Auth::user()->id;
    $oldpassword = $request->input('oldpassword');
    $newpassword = $request->input('newpassword');
    $res = DB::table('admins')->where('id',$id)->select('password')->first();
    if(!Hash::check($oldpassword, $res->password)){
        echo 2;
        exit;//原密码不对
    }
    $update = array(
      'password'  =>bcrypt($newpassword),
    );
    $result = DB::table('admins')->where('id',$id)->update($update);
    if($result){
        echo 1;exit;
    }else{
        echo 3;exit;
    }

}

你可能感兴趣的:(每日一记)