Laravel框架登录自带hash加密密码及验证密码


public function editPwd()
{

    //自定义验证
    $validator = $this->validatorPwd($this->request->all());

    if ($validator->fails()) {
        return $this->failed([], 400, '参数错误!');
    }

    $oldPwd = $this->request->get('old_password');
    $newPwd = $this->request->get('new_password');

    $id = Auth::id();
    $adminInfo = AdminRepository::selectAdmin($id);


    if(!Hash::check( $oldPwd , $adminInfo->password)){
        return $this->failed('原密码有误');
    }

    if(Hash::check( $newPwd , $adminInfo->password)){
        return $this->failed('修改密码与原密码相同');
    }

    $params = [
        'id' => $id,
        'password' => Hash::make($newPwd)
    ];

    $create = AdminRepository::editPwd($params);

    if ($create){
        return $this->message(['flag' => true]);
    }

    return $this->failed('操作失败');


    //$this->logout_web($data); //立即重新登陆
}

 

你可能感兴趣的:(知识点)