Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PasswordAttempts
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("This programme will give the user four attempts to log in.\nPress any key to begin.");
- Console.ReadKey();
- Console.Clear();
- bool choice1 = true;
- while (choice1 == true)
- {
- string exit;
- int loginAttempts = 0;
- //Simple iteration upto three times
- for (int i = 0; i < 4; i++)
- {
- Console.WriteLine("Enter Username");
- string username = Console.ReadLine();
- Console.Clear();
- Console.WriteLine("Enter Password");
- string password = Console.ReadLine();
- Console.Clear();
- if
- (username.ToLower() != "enchant" || password.ToLower() != "trademark")loginAttempts++;
- else
- break;
- }
- //Display the result
- if (loginAttempts > 2)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Login failure: You have exceeded the number of log in attempts\nPress any key to quit.");
- Console.ResetColor();
- Console.ReadKey();
- return;
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Login successful");
- Console.ResetColor();
- }
- //user informed that they can either exit the application or to go back to the beginning to try again
- Console.WriteLine("\nEnter continue to try again or enter stop to exit.");
- while (true)
- {
- exit = Console.ReadLine();
- //If statements for different outcomes
- if (exit == "stop")
- {
- return;
- }
- else if (exit == "continue")
- {
- Console.Clear();
- continue;
- }
- else
- {
- //changing colour of error message
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Sorry, make sure that the option you're choosing is spelt correctly.\nYou will be returned to the beginning\n\nPress any key");
- Console.ResetColor();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement