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

Bug: Error Occurred While Changing User Password: strtolower(): Argument #1 ($string) must be of type string, null given in NothingPersonalValidator #1171

Closed
arashsaffari opened this issue Aug 18, 2024 · 8 comments

Comments

@arashsaffari
Copy link
Contributor

arashsaffari commented Aug 18, 2024

PHP Version

8.3.10

CodeIgniter4 Version

4.5.4

Shield Version

1.1.0

Which operating systems have you tested for this bug?

macOS

Which server did you use?

apache

Database

MySQL 8

Did you customize Shield?

Yes, but I believe my changes have nothing to do with the error.

What happened?

When changing a user's password, I encounter the following error:

strtolower(): Argument #1 ($string) must be of type string, null given

This error is caused by the NothingPersonalValidator.

Steps to Reproduce

if (! $this->validate($userValidationRules))
{
return redirect()->to('/users/update/' . $id)->withInput()->with('errors', $this->validator->getErrors());
}

Expected Output

Bildschirmfoto 2024-08-18 um 03 22 27

Anything else?

No response

@arashsaffari arashsaffari added the bug Something isn't working label Aug 18, 2024
@warcooft
Copy link
Contributor

warcooft commented Aug 18, 2024

Can you show the complete code?

it looks like the email is missing or it could be that you create username only as your login credentials instead of using email.

@datamweb
Copy link
Collaborator

Hey @arashsaffari ,

In Shield, all users are required to have a unique email address, which is mandatory during the registration process. However, it's possible to log in using other identifiers besides email, such as a username, employee ID, etc.

Considering this, it seems that the user you're trying to change the password for does not have an email address associated with their account.

Please verify that the user has an email by running the following command:

php spark db:table auth_identities

Ensure that the user has a valid email (field secret).

If the user does have an email and the problem persists, please provide the minimal code necessary to reproduce the error.

@datamweb datamweb added the waiting for info Issues or pull requests that need further clarification from the author label Aug 18, 2024
@arashsaffari
Copy link
Contributor Author

arashsaffari commented Aug 20, 2024

I have an email address stored in the database. The problem is that when using $user->email, the getEmail() function in the User entity is not being called. However, when I call the $user->getEmail() function in the controller, $user->email is populated with the email address. Interestingly, when I work with $user->password_hash, the getPasswordHash() function in the entity is called, and I receive the hash. It's worth noting that I have the email stored in my auth_identities table, and my login credentials use instead of the email.

@warcooft
Copy link
Contributor

warcooft commented Aug 20, 2024

Can you show the code how you call the user data? if you call it correctly then the email displays well.

For example:

$usersModel = auth()->getProvider();
//find user where id is "7"
$user = $usersModel->find(7);
//show user email
dd($user->email); // result "example@pointerpointer.com"

@kenjis kenjis removed the bug Something isn't working label Aug 20, 2024
@kenjis
Copy link
Member

kenjis commented Aug 20, 2024

It appears that you have written incorrect code regarding User.

@warcooft
Copy link
Contributor

warcooft commented Aug 26, 2024

I can reproduce a similar error.

in my case, I added a personal field to $personalFields where the type of the field or its value is an integer. To prevent this error, we should cast the personal field value to a string.

@warcooft
Copy link
Contributor

I can reproduce the error in this issue.

It seems you added a personal field to $personalFields where the type of the field or its value is an integer. To prevent this error, we should cast the personal field value to a string.

In my case, it’s specifically related to $personalFields, so this situation is different.

@datamweb
Copy link
Collaborator

We did not receive the minimum code required to reproduce the issue. This issue is now closed.

@datamweb datamweb removed the waiting for info Issues or pull requests that need further clarification from the author label Aug 26, 2024
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

4 participants