Backend\Modules\Users\Installer\Installer::checkPassword PHP Метод

checkPassword() публичный Метод

Check the strength of the password
public checkPassword ( ) : string
Результат string
    public function checkPassword()
    {
        // init vars
        $password = $this->getVariable('password');
        $score = 0;
        $uniqueChars = array();
        // less then 4 chars is just a weak password
        if (mb_strlen($password) <= 4) {
            return 'weak';
        }
        // loop chars and add unique chars
        $passwordChars = str_split($password);
        foreach ($passwordChars as $char) {
            $uniqueChars[$char] = $char;
        }
        // less then 3 unique chars is just weak
        if (count($uniqueChars) < 3) {
            return 'weak';
        }
        // more then 6 chars is good
        if (mb_strlen($password) >= 6) {
            ++$score;
        }
        // more then 8 is better
        if (mb_strlen($password) >= 8) {
            ++$score;
        }
        // @todo
        // upper and lowercase?
        if (preg_match('/[a-z]/', $password) && preg_match('/[A-Z]/', $password)) {
            $score += 2;
        }
        // number?
        if (preg_match('/\\d+/', $password)) {
            ++$score;
        }
        // special char?
        if (preg_match('/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/', $password)) {
            ++$score;
        }
        // strong password
        if ($score >= 4) {
            return 'strong';
        }
        // average
        if ($score >= 2) {
            return 'average';
        }
        // fallback
        return 'weak';
    }