proengsoft / laravel-jsvalidation

Laravel Javascript Validation
MIT License
1.13k stars 175 forks source link

Validating Passwords with Password::min() rule #669

Open LocalHeroPro opened 3 years ago

LocalHeroPro commented 3 years ago

Subject of the issue

Want to use: https://laravel.com/docs/8.x/validation#validating-passwords.

Your environment

Steps to reproduce

Use:

'password' => [Password::min()],

Expected behaviour

Want to use: https://laravel.com/docs/8.x/validation#validating-passwords.

Actual behaviour

Frontend validator don't recognize that rule.

bytestream commented 3 years ago

Suggest to use #505 as that will work with unsupported rules

ElawadyNet commented 3 years ago

Use new password rules as callback like:

return [
            'password' => [
                'required',
                function ($attribute, $value, $fail) {
                    $rule = new Password(10);
                    $rule->setData(['password' => $value]);
                    $rule->uncompromised()->letters()->numbers()->mixedCase();
                    $passes = $rule->passes('password', $value);
                    $messages = $rule->message();
                    if (!$passes) {
                        $fail(__($messages[0]));
                    }
                },
            ],
        ];