diff --git a/src/Zxcvbn/Objects/Feedback.php b/src/Zxcvbn/Objects/Feedback.php index 94dae89..f18d5f1 100644 --- a/src/Zxcvbn/Objects/Feedback.php +++ b/src/Zxcvbn/Objects/Feedback.php @@ -20,6 +20,16 @@ */ public $Suggestions; + /** + * @return string|null + */ + public function getWarning(): ?string + { + if(strlen($this->Warning) == 0) + return null; + return $this->Warning; + } + /** * @param string $warning * @param array $Suggestions @@ -36,8 +46,12 @@ */ public function toArray(): array { + $warning = null; + if(strlen($this->Warning) > 0) + $warning = $this->Warning; + return [ - 'warning' => $this->Warning, + 'warning' => $warning, 'suggestions' => $this->Suggestions ]; } diff --git a/tests/test_password.php b/tests/test_password.php index 0f3ec53..bf54042 100644 --- a/tests/test_password.php +++ b/tests/test_password.php @@ -10,4 +10,41 @@ } $zxcvbn = new \Zxcvbn\zxcvbn(); - print(json_encode($zxcvbn->passwordStrength($argv[1])->toArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL); \ No newline at end of file + $results = $zxcvbn->passwordStrength($argv[1]); + print(json_encode($results->toArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL . PHP_EOL); + + switch($results->EstimatedAttackTimes->Score) + { + case \Zxcvbn\Abstracts\ScoreDefinitions::ExtremelyGuessable: + print('Score 0, The password is extremely guessable (within 10^3 guesses)' . PHP_EOL); + break; + + case \Zxcvbn\Abstracts\ScoreDefinitions::VeryGuessable: + print('Score 1, The password is very guessable (guesses < 10^6)' . PHP_EOL); + break; + + case \Zxcvbn\Abstracts\ScoreDefinitions::SomewhatGuessable: + print('Score 2, The password is somewhat guessable (guesses < 10^8), provides some protection from unthrottled online attacks' . PHP_EOL); + break; + + case \Zxcvbn\Abstracts\ScoreDefinitions::SafelyUnguessable: + print('Score 3, The password is safely unguessable (guesses < 10^10), offers moderate protection from offline slow-hash scenario' . PHP_EOL); + break; + + case \Zxcvbn\Abstracts\ScoreDefinitions::VeryUnguessable: + print('Score 4, The password is very unguessable (guesses >= 10^10) and provides strong protection from offline slow-hash scenario' . PHP_EOL); + break; + } + + + if($results->Feedback->Warning !== null) + print($results->Feedback->Warning . PHP_EOL); + + if(count($results->Feedback->Suggestions) > 0) + { + print('Here are some suggestions to improve password security' . PHP_EOL); + foreach($results->Feedback->Suggestions as $suggestion) + { + print(' - ' . $suggestion . PHP_EOL); + } + } \ No newline at end of file