Advertisement
Guest User

Untitled

a guest
Mar 31st, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 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 PasswordAttempts
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.WriteLine("This programme will give the user four attempts to log in.\nPress any key to begin.");
  14. Console.ReadKey();
  15. Console.Clear();
  16.  
  17. bool choice1 = true;
  18. while (choice1 == true)
  19. {
  20. string exit;
  21. int loginAttempts = 0;
  22.  
  23. //Simple iteration upto three times
  24. for (int i = 0; i < 4; i++)
  25. {
  26. Console.WriteLine("Enter Username");
  27. string username = Console.ReadLine();
  28. Console.Clear();
  29. Console.WriteLine("Enter Password");
  30. string password = Console.ReadLine();
  31. Console.Clear();
  32.  
  33. if
  34.  
  35. (username.ToLower() != "enchant" || password.ToLower() != "trademark")loginAttempts++;
  36.  
  37.  
  38. else
  39.  
  40.  
  41. break;
  42.  
  43. }
  44.  
  45. //Display the result
  46. if (loginAttempts > 2)
  47. {
  48. Console.ForegroundColor = ConsoleColor.Red;
  49. Console.WriteLine("Login failure: You have exceeded the number of log in attempts\nPress any key to quit.");
  50. Console.ResetColor();
  51. Console.ReadKey();
  52. return;
  53. }
  54. else
  55. {
  56. Console.ForegroundColor = ConsoleColor.Green;
  57. Console.WriteLine("Login successful");
  58. Console.ResetColor();
  59. }
  60.  
  61. //user informed that they can either exit the application or to go back to the beginning to try again
  62. Console.WriteLine("\nEnter continue to try again or enter stop to exit.");
  63. while (true)
  64. {
  65.  
  66.  
  67. exit = Console.ReadLine();
  68. //If statements for different outcomes
  69.  
  70.  
  71. if (exit == "stop")
  72. {
  73.  
  74. return;
  75. }
  76. else if (exit == "continue")
  77. {
  78. Console.Clear();
  79. continue;
  80.  
  81. }
  82. else
  83. {
  84. //changing colour of error message
  85. Console.ForegroundColor = ConsoleColor.Red;
  86. 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");
  87. Console.ResetColor();
  88.  
  89. }
  90. }
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement