一部のアプリケーション (または Web サイト) は、入力時にパスワードの複雑さを計算します。
通常、赤いバーが表示され、パスワードが長くなるとオレンジ、緑、さらに緑になり、より多くの文字クラス (小文字、大文字、句読点、数字など) が含まれます。
パスワードの複雑さを確実に計算するにはどうすればよいですか?
私は次のアルゴリズムを思いつきましたが、7 文字しかないため、Password1!「非常に強い」と「弱い」と評価されるという事実が懸念されます。]@feé:m
private int GetPasswordComplexity(string password)
{
if (password.Length <= 4)
return 1;
int complexity = 0;
int digit = 0;
int letter = 0;
int cap = 0;
int other = 0;
for (int i = 0; i < password.Length; i++)
{
if (char.IsDigit(password[i]) && i!=password.Length-1)
digit = 1;
else if (char.IsLower(password[i]))
letter = 1;
else if (char.IsUpper(password[i]) && i!=0)
cap = 1;
else
other = 1;
}
complexity = digit + letter + cap + other;
if (password.Length <= 7)
complexity = Math.Min(3, complexity);
return complexity;
}