elena1234

Login

Sep 25th, 2020
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4.  
  5. class LogIn
  6. {
  7.     static void Main()
  8.     {
  9.  
  10.         string userName = Console.ReadLine();
  11.         char [] userArray = userName.ToCharArray();
  12.         var count = 1;
  13.         for (int i = 0; i<userArray.Length/2; i++)
  14.         {
  15.             char a = userArray[i];
  16.             char b = userArray[userArray.Length - i - 1];
  17.             userArray[i] = b;
  18.             userArray[userArray.Length - i - 1] = a;
  19.         }
  20.  
  21.        string password = Console.ReadLine();
  22.         char[] passwordArray = password.ToCharArray();
  23.        
  24.             while (!passwordArray.SequenceEqual( userArray) && count <= 3)
  25.             {
  26.                 Console.WriteLine("Incorrect password. Try again.");
  27.                 count++;
  28.                 password = Console.ReadLine();
  29.                 passwordArray = password.ToCharArray();
  30.             }
  31.              if (!passwordArray.SequenceEqual(userArray) && count==4)
  32.              {
  33.                Console.WriteLine($"User {userName} blocked!");
  34.              }
  35.  
  36.         if (passwordArray.SequenceEqual(userArray))
  37.         {
  38.             Console.WriteLine($"User {userName} logged in.");  
  39.         }
  40.  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment