booch94

login

Jan 22nd, 2020
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2.  
  3. namespace csharpfunadamentals
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string userName = Console.ReadLine();
  10.             string password = string.Empty;
  11.  
  12.             for (int i = userName.Length-1; i >= 0; i--)
  13.             {
  14.                 char symbol = userName[i];
  15.                 password += symbol;
  16.             }
  17.             for (int i = 0; i < 4; i++)
  18.             {
  19.                 string currentPassword = Console.ReadLine();
  20.                 if(currentPassword == password)
  21.                 {
  22.                     Console.WriteLine($"User {userName} logged in.");
  23.                     break;
  24.                 }
  25.                 else if (password != currentPassword && i >= 0 && i < 3)
  26.                 {
  27.                     Console.WriteLine("Incorrect password. Try again.");
  28.                 }
  29.                 else if (password != currentPassword && i == 3)
  30.                 {
  31.                     Console.WriteLine($"User {userName} blocked!");
  32.                 }
  33.             }
  34.         }
  35.     }
  36. }
Add Comment
Please, Sign In to add comment