// Created on savesnippets.com · https://savesnippets.com/UFDplBpE8b6QQI = 8) $score++; if ($len >= 12) $score++; if ($len >= 16) $score++; if (preg_match('/[A-Z]/', $pw) && preg_match('/[a-z]/', $pw) && preg_match('/\d/', $pw)) $score++; if (preg_match('/[^A-Za-z0-9]/', $pw)) $score++; static $blocklist = ['password','12345678','qwerty','letmein','welcome','admin','iloveyou']; if (in_array(strtolower($pw), $blocklist, true)) return [0, 'Common password — pick another']; $score = min($score, 4); $label = ['Very weak','Weak','OK','Strong','Very strong'][$score]; return [$score, $label]; } print_r(scorePassword('hunter2')); // [0, "Very weak"] print_r(scorePassword('Tr0ub4dor&3')); // [3, "Strong"] print_r(scorePassword('correct horse battery staple')); // [4, "Very strong"]