Advertisement
Guest User

Untitled

a guest
Oct 7th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2.  
  3. static class StringHelper
  4. {
  5.  
  6.     public static string ReverseString(string s)
  7.     {
  8.         char[] arr = s.ToCharArray();
  9.         Array.Reverse(arr);
  10.         return new string(arr);
  11.     }
  12. }
  13.  
  14.     class Program
  15. {
  16.     static void Main(string[] args)
  17.     {
  18.  
  19.         string username = Console.ReadLine();
  20.  
  21.         int possibleTryis = 4;
  22.  
  23.  
  24.         int block = 0;
  25.  
  26.         for (int i = 0; i < possibleTryis; i++)
  27.         {
  28.             string password = Console.ReadLine();
  29.             block++;
  30.  
  31.             if (password == (StringHelper.ReverseString($"{username}")))
  32.             {
  33.                 Console.WriteLine($"User {username} logged in.");
  34.                 break;
  35.             }
  36.             else if (block >= 4)
  37.             {
  38.                 Console.WriteLine($"User {username} blocked!");
  39.                 break;
  40.             }
  41.  
  42.             else if (password != "Mecho")
  43.             {
  44.                 Console.WriteLine("Incorrect password. Try again.");
  45.  
  46.  
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement