Teo_Yanchev

5.Login - C# Fundamentals

Sep 17th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. using System;
  2.  
  3. namespace demo
  4. {
  5. class Program
  6. {
  7. static void Main()
  8. {
  9. string username = Console.ReadLine();
  10. string password = string.Empty;
  11. int count = 0;
  12. bool isLoged = true;
  13. for (int i = username.Length - 1; i >= 0; i--)
  14. {
  15. password += username[i];
  16. }
  17.  
  18. string command = Console.ReadLine();
  19.  
  20. while (password != command)
  21. {
  22. count += 1;
  23. if (count > 3)
  24. {
  25. Console.WriteLine($"User {username} blocked!");
  26. isLoged = false;
  27. break;
  28. }
  29. Console.WriteLine("Incorrect password. Try again.");
  30. command = Console.ReadLine();
  31. }
  32. if (isLoged)
  33. {
  34. Console.WriteLine($"User {username} logged in.");
  35. }
  36.  
  37. }
  38. }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment