dragonbs

Login

Feb 2nd, 2023
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. string username = Console.ReadLine();
  2. var password = new string(username.ToCharArray().Reverse().ToArray());
  3. int attempts = 0;
  4.  
  5. for (int i = 1; i <= 3; i++)
  6. {
  7.     string guess = Console.ReadLine();
  8.     if (guess != password)
  9.     {
  10.         Console.WriteLine("Incorrect password. Try again.");
  11.         attempts++;
  12.         if (attempts == 3)
  13.         {
  14.             Console.WriteLine($"User {username} blocked!");
  15.         }
  16.     }
  17.     else if (guess == password)
  18.     {
  19.         Console.WriteLine($"User {username} logged in.");
  20.         break;
  21.     }
  22. }
  23.  
  24. //while (true)
  25. //{
  26. //    string guess = Console.ReadLine();
  27. //    if (guess == password)
  28. //    {
  29. //        Console.WriteLine($"User {username} logged in.");
  30. //        return;
  31. //    }
  32. //    else if (guess != password)
  33. //    {
  34. //        Console.WriteLine("Incorrect password. Try again.");
  35. //        attempts++;
  36. //        if (attempts == 3)
  37. //        {
  38. //            Console.WriteLine($"User {username} blocked!");
  39. //            break;
  40. //        }
  41. //    }
  42. //}
Advertisement
Add Comment
Please, Sign In to add comment