Skip to content

Commit c6c2abe

Browse files
authored
Merge pull request #527 from kenjis/fix-minimumPasswordLength
fix: minimum password length check
2 parents 3aeafc8 + df01dd7 commit c6c2abe

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Authentication/Passwords/CompositionValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function check(string $password, ?User $user = null): Result
3232
throw AuthenticationException::forUnsetPasswordLength();
3333
}
3434

35-
$passed = strlen($password) >= $this->config->minimumPasswordLength;
35+
$passed = mb_strlen($password, 'UTF-8') >= $this->config->minimumPasswordLength;
3636

3737
if (! $passed) {
3838
return new Result([

tests/Unit/CompositionValidatorTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,23 @@ public function testCheckFalse(): void
4545
$result = $this->validator->check($password);
4646

4747
$this->assertFalse($result->isOK());
48-
$this->assertSame(lang('Auth.errorPasswordLength', [$this->config->minimumPasswordLength]), $result->reason());
48+
$this->assertSame(
49+
lang('Auth.errorPasswordLength', [$this->config->minimumPasswordLength]),
50+
$result->reason()
51+
);
52+
}
53+
54+
public function testCheckFalseMultibyte(): void
55+
{
56+
$password = '🍣😀';
57+
58+
$result = $this->validator->check($password);
59+
60+
$this->assertFalse($result->isOK());
61+
$this->assertSame(
62+
lang('Auth.errorPasswordLength', [$this->config->minimumPasswordLength]),
63+
$result->reason()
64+
);
4965
}
5066

5167
public function testCheckTrue(): void

0 commit comments

Comments
 (0)