The policies im trying to apply are that it has to be 3 characters long, that it must include a lower case letter, an upper case letter and a number in any order. Im trying to use it as a method to read in a password set by the user for an assignment.I have written as much as i can to emiminate errors but i cant figure out a way to apply said policies. this is what i have so far... Any help would be greatly appreciated
private static string readPass() { //readpass method to read in password of 1 lower case, 1 upper case & 1 number
bool validInput = true;
char letterUserInput; //letter from string
int asciiCodeLetter; //number code for letter
string userInput;
do {
validInput = true;
userInput = Console.ReadLine();
try {
if (userInput.Length < 1) {
validInput = false;
Console.WriteLine("You have just pressed Enter Please Enter a valid Password");
} //if check length
else if (userInput.Length > 1 && userInput.Length < 3) {
validInput = false;
Console.WriteLine("Password Is Too Short. Please Enter Valid Password");
} //if check length too short
else if (userInput.Length > 3)
{
validInput = false;
Console.WriteLine("Password Is Too Long. Please Enter A Valid Password");
} //if check length too short
for (int i = 0; i < userInput.Length; i++) //take each letter in turn from string
{
letterUserInput = userInput[i];
asciiCodeLetter = Convert.ToInt16(letterUserInput);
if (asciiCodeLetter < 48 || asciiCodeLetter > 57)
{
validInput = false;
Console.WriteLine("You have used an invalid character.\n Password Must Contain 1 Upper Case, 1 Lower Case letter and 1 Number)");
} //character check with ASCII
}
}
catch
{
validInput = false;
Console.WriteLine("An unspecified error has occured");
} //catch
if (validInput == false) Console.Write("Invalid Password. Please Enter Again = ");
} while (validInput == false); // do. repeat entry if invalid
return userInput;
}