Skip to content

Commit c794d95

Browse files
authored
Merge pull request #425 from arif-rh/fix-nothingPersonalValidator
2 parents 25f6155 + 117a856 commit c794d95

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/Authentication/Passwords/NothingPersonalValidator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ protected function isNotPersonal(string $password, ?User $user): bool
114114
$haystacks = $this->strip_explode($password);
115115

116116
foreach ($haystacks as $haystack) {
117-
if (empty($haystack) || in_array($haystack, $trivial, true)) {
118-
continue; //ignore trivial words
117+
if (empty($haystack) || in_array($haystack, $trivial, true) || mb_strlen($haystack, 'UTF-8') < 3) {
118+
continue; // ignore trivial words
119119
}
120120

121121
foreach ($needles as $needle) {
122-
if (empty($needle) || in_array($needle, $trivial, true)) {
122+
if (empty($needle) || in_array($needle, $trivial, true) || mb_strlen($needle, 'UTF-8') < 3) {
123123
continue;
124124
}
125125

tests/Unit/NothingPersonalValidatorTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,34 @@ public function testTrueWhenNoUsername(): void
119119
$this->assertTrue($result->isOK());
120120
}
121121

122+
public function testTrueForAllowedTooSmallMatch(): void
123+
{
124+
$user = new User([
125+
'email' => 'xxx@example.com',
126+
'username' => 'john doe',
127+
]);
128+
129+
$password = 'xx-test@123';
130+
131+
$result = $this->validator->check($password, $user);
132+
133+
$this->assertTrue($result->isOK());
134+
}
135+
136+
public function testFalseForSensibleMatch(): void
137+
{
138+
$user = new User([
139+
'email' => 'xxx@example.com',
140+
'username' => 'john doe',
141+
]);
142+
143+
$password = 'xxx-test@123';
144+
145+
$result = $this->validator->check($password, $user);
146+
147+
$this->assertFalse($result->isOK());
148+
}
149+
122150
/**
123151
* The dataProvider is a list of passwords to be tested.
124152
* Some of them clearly contain elements of the username.

0 commit comments

Comments
 (0)