public function PasswordStrength::passwordStrength in Password Strength 8.2
Calculate password strength via non-overlapping minimum entropy patterns.
Parameters
string $password: Password to measure.
array $userInputs: Optional user inputs.
Return value
array Strength result array with keys: password entropy match_sequence score
File
- src/
PasswordStrength.php, line 45
Class
Namespace
Drupal\password_strengthCode
public function passwordStrength($password, array $userInputs = array()) {
$timeStart = microtime(TRUE);
if (strlen($password) === 0) {
$timeStop = microtime(TRUE) - $timeStart;
return $this
->result($password, 0, array(), 0, array(
'calc_time' => $timeStop,
));
}
// Get matches for $password.
$matches = $this->matcher
->getMatches($password, $userInputs);
// Calcuate minimum entropy and get best match sequence.
$entropy = $this->searcher
->getMinimumEntropy($password, $matches);
$bestMatches = $this->searcher->matchSequence;
// Calculate score and get crack time.
$score = $this->scorer
->score($entropy);
$metrics = $this->scorer
->getMetrics();
$timeStop = microtime(TRUE) - $timeStart;
// Include metrics and calculation time.
$params = array_merge($metrics, array(
'calc_time' => $timeStop,
));
return $this
->result($password, $entropy, $bestMatches, $score, $params);
}