Advertisement
Guest User

Untitled

a guest
Jun 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Console_App_2
  5. {
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. var users = new List<User>
  11. {
  12. new User // Riley
  13. {
  14. Username = "rileyhempel",
  15. Password = "test",
  16. QandA = new QandA()
  17. {
  18. Question = "What Premier League soccer team do you go for?",
  19. Answer = "Chelsea"
  20. }
  21. },
  22.  
  23. new User // Steph
  24. {
  25. Username = "stephgolland",
  26. Password = "test2",
  27. QandA = new QandA()
  28. {
  29. Question = "What is your favourite animal?",
  30. Answer = "Horse"
  31. }
  32. },
  33.  
  34. new User // Jordan
  35. {
  36. Username = "jordanberlyn",
  37. Password = "test3",
  38. QandA = new QandA()
  39. {
  40. Question = "What state / city do you live in?",
  41. Answer = "Queensland Brisbane"
  42. }
  43. },
  44. };
  45. // Introduction
  46. Console.ForegroundColor = ConsoleColor.Cyan;
  47. Console.WriteLine("Hello!");
  48. Console.WriteLine("Welcome to the security test.");
  49. Console.WriteLine("To begin, please enter your Username and Password.");
  50.  
  51. // Username
  52. Console.ForegroundColor = ConsoleColor.DarkCyan;
  53. Console.WriteLine("Username:");
  54. Console.ForegroundColor = ConsoleColor.Gray;
  55. var username = Console.ReadLine();
  56. var user = users.Find(i => i.Username == username);
  57. if (user == null)
  58. {
  59. Console.ForegroundColor = ConsoleColor.Red;
  60. Console.WriteLine("Woops! Wrong Username. Try again.");
  61. Main();
  62. }
  63.  
  64. // Password
  65. Console.ForegroundColor = ConsoleColor.DarkCyan;
  66. Console.WriteLine("Password:");
  67. Console.ForegroundColor = ConsoleColor.Black;
  68. var password = Console.ReadLine();
  69. if (password != user.Password)
  70. {
  71. Console.ForegroundColor = ConsoleColor.Red;
  72. Console.WriteLine("Woops! Wrong Password. Try again.");
  73. Main();
  74. }
  75.  
  76. // Security Question Introduction
  77. Console.Clear();
  78. Console.ForegroundColor = ConsoleColor.Cyan;
  79. Console.WriteLine($"Welcome {user.Username}.");
  80. Console.WriteLine("Before we allow full access to your account, please take the time to answer the security question.");
  81. Console.WriteLine("Press 'enter' to continue.");
  82. Console.ReadLine();
  83. Console.Clear();
  84.  
  85. // Security Question
  86. Console.ForegroundColor = ConsoleColor.Green;
  87. Console.WriteLine("Security Question:");
  88. Console.ForegroundColor = ConsoleColor.Cyan;
  89. Console.WriteLine($"{user.QandA.Question}");
  90. Console.ResetColor();
  91. var answer = Console.ReadLine();
  92. if (answer != user.QandA.Answer)
  93. {
  94. Console.ForegroundColor = ConsoleColor.Red;
  95. Console.WriteLine("Incorrect answer. Press Enter to log out and try again.");
  96. Console.ResetColor();
  97. Console.ReadLine();
  98. Console.Clear();
  99. Main();
  100. }
  101.  
  102. // Login
  103. Console.Clear();
  104. Console.ForegroundColor = ConsoleColor.Green;
  105. Console.WriteLine("You have successfully logged in!");
  106. Console.ForegroundColor = ConsoleColor.Cyan;
  107. Console.WriteLine("What would you like to do?");
  108. }
  109.  
  110. public class User
  111. {
  112. public string Username;
  113. public string Password;
  114. public QandA QandA;
  115. }
  116. public class QandA // Question and Answer
  117. {
  118. public string Question; //
  119. public string Answer; //
  120. }
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement