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

Support for assigning validation data to strong_password method #222

Merged
merged 4 commits into from
May 8, 2020

Conversation

michalsn
Copy link
Contributor

@michalsn michalsn commented May 5, 2020

This PR makes it possible to take parameters from the validation data array or just like before when this parameter is not available from request.

I made changes that will work in both cases. When using strong_password everything is working as before but when using strong_password[] we will use data provided by the validation class.

This will work even if in the future CodeIgniter will pass validation data to the rules without a need of using a special syntax [].

This approach doesn't break any compatibility for people who use strong_password right now, so it can be safely used without the need for changes in the developer's code.

]);

$result = $this->validation->withRequest($request)->run();
$this->assertTrue($result);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this return false now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in this test I'm using strong_password[], so validation class grabs data from request and passes it to this rule (as a $data parameter).

@lonnieezell lonnieezell merged commit a257846 into lonnieezell:develop May 8, 2020
@nicojmb
Copy link

nicojmb commented May 8, 2020

Hi, i tested in my enviromento and workds, but erorr message when passord is not strong is:
"Validation.strong_password" and must be "Auth.*********"

i'think that "strong_pasword" rule should be like this:

/**
     * A validation helper method to check if the passed in
     * password will pass all of the validators currently defined.
     *
     * Handy for use in validation, but you will get a slightly
     * better security if this is done manually, since you can
     * personalize based on a specific user at that point.
     *
     * @param string      $str
     * @param string      $fields
     * @param array|null  $data
     * @param string|null $error 
     *
     * @return bool
     */
    public function strong_password(string $str, string $fields, array $data, string &$error = null)
    {
        $config = config('Auth');
        $checker = \Config\Services::passwords();

        $fields = array_merge($config->validFields, $config->personalFields);
        $fields[] = 'password';

        $user = new \Myth\Auth\Entities\User(array_merge($fields, $data));

        $result = $checker->check($str, $user);

        if ($result === false) {
            $error = $checker->error();
        }

        return $result;
    }

$data variable is always filled.

@michalsn
Copy link
Contributor Author

michalsn commented May 8, 2020

@nicojmb if you use a rule strong_password[] then $data is filled, but when you use strong_password it's not.

I couldn't get the error with Validation.strong_password. Please open a issue for this with some details of your use case - thanks.

@michalsn michalsn deleted the validation_rules branch May 15, 2020 10:39
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

Successfully merging this pull request may close these issues.

3 participants