PasswordStrength.php in Password Strength 8.2
File
src/PasswordStrength.php
View source
<?php
namespace Drupal\password_strength;
use ZxcvbnPhp\Scorer;
use ZxcvbnPhp\Searcher;
class PasswordStrength {
protected $scorer;
protected $searcher;
protected $matcher;
public function __construct() {
$this->searcher = new Searcher();
$this->scorer = new Scorer();
$this->matcher = new Matcher();
}
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,
));
}
$matches = $this->matcher
->getMatches($password, $userInputs);
$entropy = $this->searcher
->getMinimumEntropy($password, $matches);
$bestMatches = $this->searcher->matchSequence;
$score = $this->scorer
->score($entropy);
$metrics = $this->scorer
->getMetrics();
$timeStop = microtime(TRUE) - $timeStart;
$params = array_merge($metrics, array(
'calc_time' => $timeStop,
));
return $this
->result($password, $entropy, $bestMatches, $score, $params);
}
protected function result($password, $entropy, $matches, $score, $params = array()) {
$r = array(
'password' => $password,
'entropy' => $entropy,
'match_sequence' => $matches,
'score' => $score,
);
return array_merge($params, $r);
}
}