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

fix: strong_password rule fails when the personal field contains an integer value. #1183

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

warcooft
Copy link
Contributor

@warcooft warcooft commented Aug 26, 2024

Description

strong_password rule fails when the personal field contains an integer value. so, we must convert the personal field's data type to a string. See #1171 (comment)

Screenshot 2024-08-26 at 13 45 08

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@warcooft warcooft changed the title TypeError: strtolower() Argument #1 ($string) must be of type string, int given fix: TypeError strtolower() Argument #1 ($string) must be of type string, int given Aug 26, 2024
@datamweb
Copy link
Collaborator

@warcooft Thank you for submitting the PR. Could you please provide a step-by-step explanation of how to reproduce the issue?

I was unable to reproduce the issue for the value employee_id, which is an number.

    public array $personalFields = [
        //'f_name',
        'employee_id'
    ];
Data of Table "users":

+----+----------+--------+----------------+--------+-------------+--------------------+--------------------+------------+-------------+
| id | username | status | status_message | active | last_active | created_at         | updated_at         | deleted_at | employee_id |
+----+----------+--------+----------------+--------+-------------+--------------------+--------------------+------------+-------------+
| 6  | datamweb |        |                | 1      |             | 2024-08-26 20:4... | 2024-08-26 20:4... |            | 30303030    |
+----+----------+--------+----------------+--------+-------------+--------------------+--------------------+------------+-------------+

@warcooft
Copy link
Contributor Author

warcooft commented Aug 26, 2024

Step to Reproduce

make sure field employee_id set data type to INT or TINYINT

$fields = [
    'employee_id' => ['type' => 'TINYINT', 'default' => 1],
];

Login first! then add this to your controller.

  public function index()
  {
        //login first
        $data = [
            'password'      => '12345678Aa',
            'password_confirm' => '12345678Aa',
            'old_password' => 'P@ssw0rd' //change this with your password
        ];

        if (!$this->validateData($data, $this->getValidationRules())) {
            dd($this->validator->getErrors());
        }

        $result = auth()->check([
            'email'    => auth()->user()->email,
            'password' => $data['old_password'],
        ]);

        if (!$result->isOK()) {
            // wrong password
            dd('wrong password');
        }

        // Success!
        $users = auth()->getProvider();

        $user = auth()->user()->fill([
            'password' => $data['password']
        ]);

        $users->save($user);
}

 protected function getValidationRules(): array
 {
        return setting('Validation.changePassword') ?? [
            'password' => [
                'label' => 'Auth.password',
                'rules' => 'required|strong_password',
            ],
            'password_confirm' => [
                'label' => 'Auth.passwordConfirm',
                'rules' => 'required|matches[password]',
            ],
        ];
  }

the error seems to arise from the strong_password rule.

@warcooft warcooft changed the title fix: TypeError strtolower() Argument #1 ($string) must be of type string, int given fix: strong_password rule fails when the personal field contains an integer value. Aug 26, 2024
@kenjis kenjis added tests needed Pull requests that need tests bug Something isn't working labels Aug 26, 2024
@kenjis
Copy link
Member

kenjis commented Aug 26, 2024

Important

We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works.

First, please write test code that reproduces the error.
And add a commit to fix the error.
Then, the test should pass, and it proves the error is surely fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tests needed Pull requests that need tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants