So I am trying to write a program that asks for you to create a password. I have a block of code that checks to see if the string entered by the user contains a symbol. I have the code set to exit the loop when the boolean value 'validPassword' equals true.
string pleaseenterapassword = "Create a password:";
bool validPassword = false;
Console.WriteLine(pleaseenterapassword); // Writes to the screen "Create a password:"
string password = Console.ReadLine(); //Sets the text entered in the Console into the string 'password'
bool containsAtLeastOneSymbol = password.Any(char.IsSymbol);
if (containsAtLeastOneSymbol == false) // Checks if your password contains at least one symbol
{
Console.WriteLine("Your password must contain at least one symbol.");
validPassword = false;
}
This code is successful if I enter something like "Thisismypassword905+", but it does not work if I enter something like "Thisismypassword95*". I would appreciate any sort of help. Thanks in advance!
Back to your problem. I'd do it this way:
You could use
PasswordValidator
from Asp.Net Identity Framework but if you don't want to introduce such dependency is easy to extract the behavior using a couple of classes:The validator
Validation Result
Your main function:
Hope this helps!
From msdn:
Braille patterns.
Dingbats
Update: For juharr, who asked why does the '*' is not in the category of MathSymbol. The asterisk is not in the category of MathSymbols with this snippet you can check it. Or see this fiddle