config = $config; } public function checkStrength(string $password): bool { $minLength = $this->config->get('passwordStrengthLength'); if ($minLength) { if (mb_strlen($password) < $minLength) { return false; } } $requiredLetterCount = $this->config->get('passwordStrengthLetterCount'); if ($requiredLetterCount) { $letterCount = 0; foreach (str_split($password) as $c) { if (ctype_alpha($c)) { $letterCount++; } } if ($letterCount < $requiredLetterCount) { return false; } } $requiredNumberCount = $this->config->get('passwordStrengthNumberCount'); if ($requiredNumberCount) { $numberCount = 0; foreach (str_split($password) as $c) { if (is_numeric($c)) { $numberCount++; } } if ($numberCount < $requiredNumberCount) { return false; } } $bothCases = $this->config->get('passwordStrengthBothCases'); if ($bothCases) { $ucCount = 0; $lcCount = 0; foreach (str_split($password) as $c) { if (ctype_alpha($c) && $c === mb_strtoupper($c)) { $ucCount++; } if (ctype_alpha($c) && $c === mb_strtolower($c)) { $lcCount++; } } if (!$ucCount || !$lcCount) { return false; } } return true; } }