且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不必要的验证规则应用于密码重置

更新时间:2022-12-11 22:20:43

返回错误的原因是因为 PasswordBroker 要求密码的最小长度为8个字符,因此即使尽管您的表单验证已通过,但 PasswordBroker 中的验证未通过.

The reason that you're getting the error back is because the PasswordBroker expects a password with a minimum length of 8 characters so even though your form validation is passing, the validation in the PasswordBroker isn't.

解决此问题的一种方法是在 ResetPasswordController 中重写 broker()方法,并将您自己的验证器传递给它:

One way to get around this would be to override the broker() method in your ResetPasswordController and pass your own validator to it:

public function broker()
{
    $broker = Password::broker();

    $broker->validator(function ($credentials) {
        return $credentials['password'] === $credentials['password_confirmation'];
    });

    return $broker;
}

以上内容与 PasswordBroker 本身的操作基本相同,只是也没有对字符串长度进行检查.

The above is essentially the same as what's going on in the PasswordBroker itself, just without the string length check as well.

别忘了将 Password 门面导入到您的控制器中:

Don't forget to import the Password facade into your controller:

use Illuminate\Support\Facades\Password;


这不是必需的,但出于良好的考虑,我建议您也更新 resources/lang/zh-cn/passwords.php 文件中的 password 错误消息