Skip to content

Commit

Permalink
fix: error on PHP 8.1
Browse files Browse the repository at this point in the history
ErrorException: strtolower(): Passing null to parameter codeigniter4#1 ($string) of type string is deprecated
  • Loading branch information
kenjis authored and davidnsai committed Feb 21, 2023
1 parent eb509f5 commit 6404bb0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Authentication/Passwords/NothingPersonalValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function check(string $password, $user = null): Result
*/
protected function isNotPersonal($password, $user)
{
$userName = \strtolower($user->username);
$userName = \strtolower($user->username ?? '');
$email = \strtolower($user->email);
$valid = true;

Expand Down Expand Up @@ -164,6 +164,10 @@ protected function isNotPersonal($password, $user)
*/
protected function isNotSimilar($password, $user)
{
if ($user->username === null) {
return true;
}

$maxSimilarity = (float) $this->config->maxSimilarity;
// sanity checking - working range 1-100, 0 is off
if ($maxSimilarity < 1) {
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/NothingPersonalValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ public function testTrueWhenPasswordHasNothingPersonal()
$this->assertTrue($result->isOK());
}

public function testTrueWhenNoUsername(): void
{
$config = new Auth();
$config->maxSimilarity = 50;
$config->personalFields = [
'firstname',
'lastname',
];
$this->validator = new NothingPersonalValidator($config);

$user = new User([
'email' => '[email protected]',
'firstname' => 'Joseph',
'lastname' => 'Smith',
]);

$password = 'opensesame';

$result = $this->validator->check($password, $user);

$this->assertTrue($result->isOK());
}

/**
* The dataProvider is a list of passwords to be tested.
* Some of them clearly contain elements of the username.
Expand Down

0 comments on commit 6404bb0

Please sign in to comment.