Validate.php
public static function getPasswordComplexity($password, $minLength)
    {
        $group = [
            'upper' => '/[A-Z]/',
            'lower' => '/[a-z]/',
            'number' => '/[0-9]/',
            'special' => '/[^A-Za-z0-9]/',
        ];
        $score = 0;
        $length = \strlen($password);

        if ($length < $minLength) {
            return 0;
        }

        // Increment the score for each of these conditions
        foreach ($group as $pattern) {
            if (preg_match($pattern, $password)) {
                $score++;
            }
        }

        // Penalize if there aren't at least three char types
        if ($score < 3) {
            $score--;
        }

        // Increment the score for every 2 chars longer than the minimum
        if ($length > $minLength) {
            $score += (int)floor(($length - $minLength) / 2);
        }

        return $score;
    }
public static function getPasswordComplexity($password, $minLength)
    {
        $group = [
            'upper' => '/[A-Z]/',
            'lower' => '/[a-z]/',
            'number' => '/[0-9]/',
            'special' => '/[^A-Za-z0-9]/',
        ];
        $score = 0;
        $length = \strlen($password);

        if ($length < $minLength) {
            return 0;
        }

        // Increment the score for each of these conditions
        foreach ($group as $pattern) {
            if (preg_match($pattern, $password)) {
                $score++;
            }
        }

        // Penalize if there aren't at least three char types
        if ($score < 3) {
            $score--;
        }

        // Increment the score for every 2 chars longer than the minimum
        if ($length > $minLength) {
            $score += (int)floor(($length - $minLength) / 2);
        }

        return $score;
    }
Get password complexity

@param string $password Password
@param int $minLength Minimal length
@return int Password score