Phalcon\Validation\Validator\PasswordStrength::countScore PHP Method

countScore() private method

Calculates password strength score
private countScore ( string $value ) : integer
$value string - password
return integer (1 = very weak, 2 = weak, 3 = medium, 4+ = strong)
    private function countScore($value)
    {
        $score = 0;
        $hasLower = preg_match('![a-z]!', $value);
        $hasUpper = preg_match('![A-Z]!', $value);
        $hasNumber = preg_match('![0-9]!', $value);
        if ($hasLower && $hasUpper) {
            ++$score;
        }
        if ($hasNumber && $hasLower || $hasNumber && $hasUpper) {
            ++$score;
        }
        if (preg_match('![^0-9a-zA-Z]!', $value)) {
            ++$score;
        }
        $length = mb_strlen($value);
        if ($length >= 16) {
            $score += 2;
        } elseif ($length >= 8) {
            ++$score;
        } elseif ($length <= 4 && $score > 1) {
            --$score;
        } elseif ($length > 0 && $score === 0) {
            ++$score;
        }
        return $score;
    }
PasswordStrength