Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Login
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. string username = Console.ReadLine();
  10. char[] usernameArray = username.ToCharArray();
  11. Array.Reverse(usernameArray);
  12. string reversed = string.Empty;
  13. foreach (char ch in usernameArray)
  14. {
  15. reversed += ch;
  16. }
  17. string password = Console.ReadLine();
  18.  
  19.  
  20. bool tryWhile = true;
  21. int count = 0;
  22.  
  23. while (tryWhile)
  24. {
  25. if (count < 3)
  26. {
  27. if (password != reversed)
  28. {
  29. Console.WriteLine("Incorrect password. Try again.");
  30. password = Console.ReadLine();
  31. count++;
  32.  
  33. }
  34. else if (password == reversed)
  35. {
  36. Console.WriteLine($"User {username} logged in.");
  37. tryWhile = false;
  38. }
  39. }
  40. if (count == 3)
  41. {
  42. if (password != reversed)
  43. {
  44. Console.WriteLine($"User {username} blocked!");
  45. tryWhile = false;
  46. }
  47. else if (password == reversed)
  48. {
  49. Console.WriteLine($"User {username} logged in.");
  50. tryWhile = false;
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement