我有简单的功能来重置我的密码。在我的函数中,password
值的最低要求是1 digit
,但是当我尝试更新密码时,它不会更新,当我将6 digits
放入密码时它工作正常。
我发现在vendor\laravel\framework\src\Illuminate\Auth\Passwords
passwordBroker.php
文件中有一个函数
protected function validatePasswordWithDefaults(array $credentials)
{
list($password, $confirm) = [
$credentials['password'],
$credentials['password_confirmation'],
];
return $password === $confirm && mb_strlen($password) >= 6; // here it is
}
它包含验证($password) >= 6
如何删除它,当我更改此文件时它正在工作。在我的.gitignore
vendor
文件夹中未在实时更新。解决办法是什么 ?如何覆盖此验证?
这里的参考是我的resetpassword
函数
public function resetPassword(ResetPasswordRequest $request, JWTAuth $JWTAuth)
{
$validator = Validator::make($request->all(), User::resetPasswordRules());
if ($validator->fails()) {
return response()->json([
'message' => "422 Unprocessable Entity",
'errors' => $validator->messages(),
'status_code' => 422,
]);
}
$response = $this->broker()->reset(
$this->credentials($request), function ($user, $password) {
$this->reset($user, $password);
}
);
if($response !== Password::PASSWORD_RESET) {
return response()->json([
'message' => "Internal Server Error",
'status_code' => 500,
]);
}
$user = User::where('email', '=', $request->get('email'))->first();
$user->UserDeviceData()->firstOrCreate([
'device_id' => $request->device_id
]);
return (new UserTransformer)->transform($user,[
'request_type' => 'reset_password',
'token' => $JWTAuth->fromUser($user)
]);
}
答案 0 :(得分:3)
这是解决这个问题的方法:
public function resetPassword(ResetPasswordRequest $request, JWTAuth $JWTAuth)
{
... // Validator check and json response
$broker = $this->broker();
// Replace default validation of the PasswordBroker
$broker->validator(function (array $credentials) {
return true; // Password match is already validated in PasswordBroker so just return true here
});
$response = $broker->reset(
$this->credentials($request), function ($user, $password) {
$this->reset($user, $password);
});
...
}
首先生成代理的实例,然后添加一个可调用的函数,它将用于验证而不是validatePasswordWithDefaults
。在那里你只需要返回true,因为PasswordBroker已经有一个支票$password === $confirm
。