Advertisement
Guest User

Untitled

a guest
Nov 11th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 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 PassLockBetter
  8. {
  9. class Program
  10. {
  11. static string UserName;
  12. static string Password;
  13.  
  14. static List<string> accounts = new List<string>();
  15. static List<string> userNames = new List<string>();
  16.  
  17. static int counter = 0;
  18.  
  19. static void Main(string[] args)
  20. {
  21. Start();
  22. }
  23.  
  24. static void Start()
  25. {
  26. Console.WriteLine("Type 'REGISTER' to register a new account or type 'LOGIN' to login to your existing account");
  27. string LOR = Console.ReadLine();
  28.  
  29. if (LOR == "LOGIN")
  30. {
  31. Login();
  32. }
  33.  
  34. if (LOR == "REGISTER")
  35. {
  36. Register();
  37. }
  38. }
  39.  
  40. static void Register()
  41. {
  42. bool UsrNameConf = false;
  43. bool PssWrdConf = false;
  44.  
  45. Console.WriteLine("Please enter a username (4 characters minimum length and 12 characters maximum length)");
  46. string UN = Console.ReadLine();
  47.  
  48. if (4 <= UN.Length && 12 >= UN.Length)
  49. {
  50. if (userNames.Contains(UN))
  51. {
  52. Console.WriteLine("username already exists");
  53. Register();
  54. }
  55.  
  56. else
  57. {
  58. UserName = UN;
  59. UsrNameConf = true;
  60. }
  61.  
  62. }
  63.  
  64. else
  65. {
  66. Console.WriteLine("not a valid username");
  67. Start();
  68. }
  69.  
  70. while (UsrNameConf && !PssWrdConf)
  71. {
  72. Console.WriteLine("enter a password (4 characters minimum length and 18 characters maximum length)");
  73. string PW = Console.ReadLine();
  74. if (PW.Length >= 4 && PW.Length <= 18)
  75. {
  76. Password = PW;
  77. PssWrdConf = true;
  78. }
  79.  
  80. else
  81. {
  82. Console.WriteLine("not a valid password");
  83. }
  84. }
  85.  
  86. if (UsrNameConf && PssWrdConf)
  87. {
  88. userNames.Add(UserName);
  89. accounts.Add(UserName + Password);
  90. UserName = "";
  91. Password = "";
  92. Console.WriteLine("Account successfuly registered");
  93. Start();
  94. }
  95. }
  96.  
  97. static void Login()
  98. {
  99. string PW;
  100. string UN;
  101.  
  102. Console.WriteLine("Type in your username");
  103. UN = Console.ReadLine();
  104. Console.WriteLine("Type in your password");
  105. PW = Console.ReadLine();
  106.  
  107. if (accounts.Contains(UN + PW))
  108. {
  109. Console.WriteLine("Welcome to your account " + UN);
  110. Start();
  111. }
  112. else
  113. {
  114. Console.WriteLine("Invalid password or username");
  115. counter += 1;
  116.  
  117. if (counter == 3)
  118. {
  119. Console.WriteLine("You are locked out. Wait for 10 seconds to continue ");
  120. lockedWait();
  121. Login();
  122. }
  123. else
  124. {
  125. Login();
  126. }
  127. }
  128. }
  129.  
  130. static void lockedWait()
  131. {
  132. System.Threading.Thread.Sleep(10000); //1000 = 1 SECOND
  133. }
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement