Skip to content

Commit

Permalink
Better format of user input, documenting, fixes PR 6
Browse files Browse the repository at this point in the history
  • Loading branch information
bjeavons committed Oct 8, 2014
1 parent 6080ea6 commit dc8aa91
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ require_once 'vendor/autoload.php';
```php
use ZxcvbnPhp\Zxcvbn;

$userData = array(
'Marco',
'[email protected]'
);

$zxcvbn = new Zxcvbn();
$strength = $zxcvbn->passwordStrength('password');
$strength = $zxcvbn->passwordStrength('password', $userData);
echo $strength['score'];
```

Expand Down
6 changes: 5 additions & 1 deletion src/ZxcvbnPhp/Matchers/DictionaryMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public static function match($password, array $userInputs = array())
$matches = array();
$dicts = static::getRankedDictionaries();
if (!empty($userInputs)) {
$dicts['user_inputs'] = $userInputs;
$dicts['user_inputs'] = array();
foreach ($userInputs as $rank => $input) {
$input_lower = strtolower($input);
$dicts['user_inputs'][$input_lower] = $rank;
}
}
foreach ($dicts as $name => $dict) {
$results = static::dictionaryMatch($password, $dict);
Expand Down
4 changes: 4 additions & 0 deletions test/ZxcvbnPhp/Test/ZxcvbnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ public function testZxcvbn()
$password = '123abcdefgh334123abcdefgh334123abcdefgh334';
$result = $zxcvbn->passwordStrength($password);
$this->assertEquals(4, $result['score'], "Score incorrect");

$password = '[email protected]';
$result = $zxcvbn->passwordStrength($password, array($password));
$this->assertEquals(0, $result['score'], "Score incorrect");
}
}

0 comments on commit dc8aa91

Please sign in to comment.