Red indicates errors or problems - please change your mind using red to indicate a strong password.
In addition, since you repeatedly update a color based on potentially many matches, your colors will not be as consistent as you would like.
Instead, give each of the conditions a rating, and then choose your color based on the total score:
int score = 0; if (txtPass.Text.Length < 4) score += 1; if (txtPass.Text.Length >= 6) score += 4; if (txtPass.Text.Length >= 12) score += 5; if (Regex.IsMatch(PassChar, @"[az]") && Regex.IsMatch(PassChar, @"[AZ]")) score += 2; if (Regex.IsMatch(PassChar, @"[!@#\$%\^&\*\?_~\-\(\);\.\+:]+")) score += 3; if (score < 2) { color = Color.Red; } else if (score < 6) { color = Color.Yellow; } else if (score < 12) { color = Color.YellowGreen; } else { color = Color.Green; }
Pay attention to the use of the else-if constructor, which is sometimes simpler than the one supplied using the switch or case language. (C / C ++, in particular, is prone to software errors.)
sarnold
source share