Untitled
unknown
plain_text
3 years ago
1.2 kB
13
Indexable
public static string CheckPasswordStrength(string password)
{
int length = password.Length;
int complexity = password.Distinct().Count();
bool hasUppercase = false;
bool hasLowercase = false;
bool hasDigit = false;
bool hasSpecialChar = false;
// Check if the password meets the criteria for weak password
if (length < 8 || complexity < 4 || (!password.Any(char.IsUpper) || !password.Any(char.IsLower) || !password.Any(char.IsDigit)))
{
return "Weak";
}
// Check if the password meets the criteria for fair password
if (length < 12 || complexity < 6 || (!password.Any(char.IsUpper) || !password.Any(char.IsLower) || !password.Any(char.IsDigit) || !password.Any(ch => !char.IsLetterOrDigit(ch))))
{
return "Fair";
}
// Check if the password meets the criteria for good password
if (length < 16 || complexity < 8 || (!password.Any(char.IsUpper) || !password.Any(char.IsLower) || !password.Any(char.IsDigit) || !password.Any(ch => !char.IsLetterOrDigit(ch))))
{
return "Good";
}
// If the password does not meet the criteria for any of the above categories, it is classified as strong
return "Strong";
}Editor is loading...