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 ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[,] logon = new string[5, 2]
- //initialises array and the data in the elements
- {
- {"b-fossil", "Pa55word" },
- {"c-packet", "B@nan@"},
- {"c-packet", "Cr1sps" },
- {"andy", "isalegend" },
- {"iwish", "iwasascoolasandy" }
- };
- bool login = false;
- string password = "";
- int i = 0;
- for (int tries = 0; tries < 3; tries++)
- {
- //For loop for amount of tries allowed
- Console.WriteLine("Please enter a username");
- string username = Console.ReadLine().ToLower();
- //takes input of username and converts to all lower case to avoid making the check case sensitive
- for (i = 0; i < 5; i++)
- //loop for checking each array item
- {
- if (username == logon[i, 0])
- {
- Console.WriteLine("Please enter the password for this user");
- password = Console.ReadLine();
- tries = 3;
- //sets tries to 3 so loop is cancelled if username is correct
- }
- else
- {
- Console.WriteLine("That username was not recognised. Please try again");
- username = Console.ReadLine();
- //tells user that the username they entered was not correct thus they must try again
- }
- }
- }
- for (int a = 0; a < 3; a++)
- //loop for how many times a password can be entered
- {
- if (password == logon[i, 1])
- {
- Console.WriteLine("Access Granted");
- Console.ReadLine();
- //allows access if password is correct
- }
- else
- {
- Console.WriteLine("The password you entered was incorrect. Please try again");
- password = Console.ReadLine();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement