Advertisement
unrealbg

Untitled

Sep 23rd, 2018 (edited)
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2.  
  3. namespace P05_LoginV2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string username = Console.ReadLine();
  10.             string password = Console.ReadLine();
  11.  
  12.             string reverseName = string.Empty;
  13.             int counter = 0;
  14.  
  15.             for (int i = username.Length - 1; i >= 0; i--)
  16.             {
  17.                 reverseName += username[i];
  18.             }
  19.  
  20.             while (password != reverseName)
  21.             {
  22.                 counter++;
  23.                 Console.WriteLine("Incorrect password. Try again.");
  24.                 password = Console.ReadLine();
  25.                 if (counter == 3 && password != reverseName)
  26.                 {
  27.                     Console.WriteLine($"User {username} blocked!");
  28.                     return;
  29.                 }
  30.             }
  31.  
  32.             if (password == reverseName)
  33.             {
  34.                 Console.WriteLine($"User {username} logged in.");
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement