Advertisement
Guest User

Untitled

a guest
Nov 5th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp2
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string[,] logon = new string[5, 2]
  14. //initialises array and the data in the elements
  15. {
  16. {"b-fossil", "Pa55word" },
  17. {"c-packet", "B@nan@"},
  18. {"c-packet", "Cr1sps" },
  19. {"andy", "isalegend" },
  20. {"iwish", "iwasascoolasandy" }
  21. };
  22. bool login = false;
  23.  
  24. string password = "";
  25. int i = 0;
  26. for (int tries = 0; tries < 3; tries++)
  27. {
  28. //For loop for amount of tries allowed
  29.  
  30. Console.WriteLine("Please enter a username");
  31. string username = Console.ReadLine().ToLower();
  32. //takes input of username and converts to all lower case to avoid making the check case sensitive
  33.  
  34. for (i = 0; i < 5; i++)
  35. //loop for checking each array item
  36. {
  37. if (username == logon[i, 0])
  38. {
  39. Console.WriteLine("Please enter the password for this user");
  40. password = Console.ReadLine();
  41. tries = 3;
  42. //sets tries to 3 so loop is cancelled if username is correct
  43. }
  44.  
  45. else
  46. {
  47. Console.WriteLine("That username was not recognised. Please try again");
  48. username = Console.ReadLine();
  49. //tells user that the username they entered was not correct thus they must try again
  50. }
  51. }
  52.  
  53. }
  54. for (int a = 0; a < 3; a++)
  55. //loop for how many times a password can be entered
  56. {
  57.  
  58.  
  59. if (password == logon[i, 1])
  60. {
  61. Console.WriteLine("Access Granted");
  62. Console.ReadLine();
  63. //allows access if password is correct
  64. }
  65.  
  66.  
  67. else
  68. {
  69. Console.WriteLine("The password you entered was incorrect. Please try again");
  70. password = Console.ReadLine();
  71.  
  72.  
  73. }
  74. }
  75. }
  76.  
  77.  
  78.  
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement