Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValidatioRule "strong_password" conflict validation system #210

Closed
nicojmb opened this issue Apr 24, 2020 · 3 comments
Closed

ValidatioRule "strong_password" conflict validation system #210

nicojmb opened this issue Apr 24, 2020 · 3 comments

Comments

@nicojmb
Copy link

nicojmb commented Apr 24, 2020

Hi, the strong_password rule fail with custom validation data, the validation rule always search in "post"and un my case i pasa te data yo run method.

Code Example:

`$form = $this->request->getRawInput();

            $validation =  \Config\Services::validation();

            $rules = [
                'active'       => 'required',
                'username'     => "required|alpha_numeric_space|min_length[3]|is_unique[users.username,id,$id]",
                'email'        => "required|valid_email|is_unique[users.email,id,$id]",
                'password'     => 'strong_password',
                'pass_confirm' => 'matches[password]',
                'permission'   => 'if_exist',
                'group'        => 'if_exist',
            ];

            $validation->setRules($rules);

            if ($validation->run($form) === FALSE) {

                return $this->failValidationError(json_encode($validation->getErrors()));
            }`

Error:

Argument 1 passed to Myth\Auth\Entities\User::setPassword() must be of the type string, null given, called in /home/marebluehs/www/vendor/codeigniter4/framework/system/Entity.php on line 134

@michalsn
Copy link
Contributor

michalsn commented May 3, 2020

This is a valid issue.

Sadly with the current implementation of parsing validation rules, there is no way to access the data params that were set with $validation->run($form) if this validation rule has no additional parameters.

If we would require this rule to be written like this: strong_password[], then with a little change it would work. But I guess we probably can't change that at this point.

As a workaround, I created a PR #215 to support data from getRawInput(). It should help in your case since you will be able to call $validation->run() and it will work.

But still... $validation->run($form) will be an issue so it's not an ideal solution.

@nicojmb
Copy link
Author

nicojmb commented May 4, 2020

i think that "password[]" is the better option in this case.

Maybe ci4 team modify core to allow create custom rules without parameters and with acces to $data form, like rules with params.

Regards!

@lonnieezell
Copy link
Owner

I've seen a couple of issues crop up over at CI over at the moment with this same issue, so I think always passing $data would make sense in the core. Can you open an issue over there so we don't forget about it? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants