Skip to content

Commit 2adade8

Browse files
committed
Add warning feedback from user_inputs
1 parent 7153931 commit 2adade8

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
@@ -106,6 +106,8 @@ public function getFeedback($isSoleMatch)
106106
public function getFeedbackWarning($isSoleMatch)
107107
{
108108
switch ($this->dictionaryName) {
109+
case 'user_inputs':
110+
return 'This is easy to guess based on the other inputs';
109111
case 'passwords':
110112
if ($isSoleMatch && !$this->l33t && !$this->reversed) {
111113
if ($this->rank <= 10) {

test/FeedbackTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use ZxcvbnPhp\Feedback;
77
use ZxcvbnPhp\Matchers\Bruteforce;
88
use ZxcvbnPhp\Matchers\DateMatch;
9+
use ZxcvbnPhp\Matchers\DictionaryMatch;
910
use ZxcvbnPhp\Matchers\SequenceMatch;
1011

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

0 commit comments

Comments
 (0)