Skip to content

Commit 0aa7dfa

Browse files
committed
Add warning feedback from user_inputs
1 parent f6a82ae commit 0aa7dfa

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Matchers/DictionaryMatch.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ public function getFeedback(bool $isSoleMatch): array
114114
public function getFeedbackWarning(bool $isSoleMatch): string
115115
{
116116
switch ($this->dictionaryName) {
117+
case 'user_inputs':
118+
return 'This is easy to guess based on the other inputs';
117119
case 'passwords':
118120
if ($isSoleMatch && !$this->l33t && !$this->reversed) {
119121
if ($this->rank <= 10) {

test/FeedbackTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use ZxcvbnPhp\Feedback;
99
use ZxcvbnPhp\Matchers\Bruteforce;
1010
use ZxcvbnPhp\Matchers\DateMatch;
11+
use ZxcvbnPhp\Matchers\DictionaryMatch;
1112
use ZxcvbnPhp\Matchers\SequenceMatch;
1213

1314
class FeedbackTest extends TestCase
@@ -104,4 +105,17 @@ public function testBruteforceFeedback()
104105
"bruteforce match only has the default suggestion"
105106
);
106107
}
108+
109+
public function testFeedbackFromUserInput()
110+
{
111+
$match = new DictionaryMatch('user_input_password', 0, 19, 'user_input_password', [
112+
'dictionary_name' => 'user_inputs',
113+
'matched_word' => 'user_input_password',
114+
'rank' => '1'
115+
]);
116+
$feedback = $this->feedback->getFeedback(0, [$match]);
117+
118+
$this->assertEquals('This is easy to guess based on the other inputs', $feedback['warning'], 'no warning for user input');
119+
$this->assertNotEmpty($feedback['suggestions'], 'no suggestions for user intpu');
120+
}
107121
}

0 commit comments

Comments
 (0)