Minor bug fixes

This commit is contained in:
Zi Xing 2021-09-18 08:54:08 -04:00
parent 56b5b0b51d
commit 506a63b92d
2 changed files with 53 additions and 2 deletions

View File

@ -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
];
}

View File

@ -10,4 +10,41 @@
}
$zxcvbn = new \Zxcvbn\zxcvbn();
print(json_encode($zxcvbn->passwordStrength($argv[1])->toArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);
$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);
}
}