i was trying to do password complexity test like this way but it is not working.
private void button1_Click(object sender, EventArgs e)
{
string CapsChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string LowerChars = "abcdefghijklmnopqrstuvwxyz";
string Digits = "0123456789";
string SpecialChars = "#<>!~@";
if (textBox1.Text.ContainsInvariant(CapsChars))
{
if (textBox1.Text.ContainsInvariant(LowerChars))
{
if (textBox1.Text.ContainsInvariant(Digits))
{
if (textBox1.Text.ContainsInvariant(SpecialChars))
{
MessageBox.Show("ALL Ok");
}
else
{
MessageBox.Show("No special character found");
}
}
else
{
MessageBox.Show("No digit found");
}
}
else
{
MessageBox.Show("No lower case character found");
}
}
else
{
MessageBox.Show("No upper case character found");
}
}
public static class StringExt
{
public static bool ContainsInvariant(this string sourceString, string filter)
{
return sourceString.ToLowerInvariant().Contains(filter);
}
}
i like to test in such a way that password must have one caps character and one lower case character and one digit and one special character and pwd length has to be more than 8. looking for suggestion how to achieve it. just wondering can we achieve the same using LINQ? thanks