I am trying to make a password checker in C#, and when I enter smaller values for the username and password, the program executes as expected, but when I enter larger values, the program doesn't do anything. The if statements are not validating for larger inputs. Here is my code:
Console.Write("Set a username: ");
string username = Console.ReadLine();
Console.Write("Set a password: ");
string password = Console.ReadLine();
Console.WriteLine("Are you sure that you want these as your username and password? (Y/N)");
Console.Write("Enter here: ");
string decision = Console.ReadLine();
if (decision == "Y" || decision == "y")
{
Console.Write("Enter your username: ");
string inputUser = Console.ReadLine();
Console.Write("Enter your password: ");
string inputPass = Console.ReadLine();
if (inputUser == username && inputPass == password)
{
Console.WriteLine("Username and password match correctly! Restart the program to try again.");
}
else if (inputUser == username && inputPass != password || inputUser != username && inputPass == password)
{
int i = 0;
while (inputUser == username && inputPass != password || inputUser != username && inputPass == password && i < 2)
{
Console.WriteLine("Username or password don't match correctly. Please try again.");
Console.Write("Enter your username: ");
inputUser = Console.ReadLine();
Console.Write("Enter your password: ");
inputPass = Console.ReadLine();
i++;
if (inputUser == username && inputPass == password)
{
Console.WriteLine("Username and password match correctly! Restart the program to try again.");
break;
}
if (i >= 2)
{
Console.WriteLine("Too many attempts. Please restart program to try again.");
break;
}
}
}
There are no error messages from visual studio, so I'm not sure what to do.
Aucun commentaire:
Enregistrer un commentaire