Skip to content

Commit 97650bc

Browse files
authored
Merge pull request #3 from cgauge/case-sensitive
Case insensitive word validation for blacklist
2 parents 3e7380b + eacce29 commit 97650bc

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Rule/Blacklist.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public function __construct(array $words, string $encoding = 'utf8')
4646

4747
public function __invoke(string $password) : void
4848
{
49+
$password = mb_strtolower($password, $this->encoding);
4950
foreach ($this->words as $word) {
51+
$word = mb_strtolower($word, $this->encoding);
5052
if (mb_strpos($password, $word, 0, $this->encoding) !== false) {
5153
throw InBlacklist::contains($word);
5254
}

tests/Rule/BlacklistTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,15 @@ public function test_it_can_validate_a_blacklist()
3636

3737
$blacklist($password);
3838
}
39+
40+
public function test_it_is_case_insensitive()
41+
{
42+
self::expectException(InvalidPassword::class);
43+
44+
$lowerCasePassword = 'blackliststring';
45+
$password = 'Blackliststring';
46+
$blacklist = new Blacklist([$lowerCasePassword]);
47+
48+
$blacklist($password);
49+
}
3950
}

0 commit comments

Comments
 (0)