Advertisement
aggressiveviking

Untitled

Mar 13th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _05.Login
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string userName = Console.ReadLine();
  10.  
  11.             int error = 0;
  12.             int count = 0;
  13.  
  14.             bool login = true;
  15.  
  16.             while (login)
  17.             {
  18.                 string password = Console.ReadLine();
  19.  
  20.                 if (userName.Length != password.Length)
  21.                 {
  22.                     if (error == 3)
  23.                     {
  24.                         Console.WriteLine($"User {userName} blocked!");
  25.                         login = false;
  26.                         break;
  27.                     }
  28.  
  29.                     Console.WriteLine("Incorrect password. Try again.");
  30.                     error++;
  31.                 }
  32.                 else
  33.                 {
  34.                     for (int i = 0; i < userName.Length; i++)
  35.                     {
  36.                         if (userName[i] == password[userName.Length - i - 1])
  37.                         {
  38.                             count++;
  39.  
  40.                             if (count == userName.Length)
  41.                             {
  42.                                 Console.WriteLine($"User {userName} logged in.");
  43.                                 login = false;
  44.                                 break;
  45.                             }
  46.  
  47.                         }
  48.                         else
  49.                         {
  50.                             if (error == 3)
  51.                             {
  52.                                 Console.WriteLine($"User {userName} blocked!");
  53.                                 login = false;
  54.                                 break;
  55.                             }
  56.  
  57.                             Console.WriteLine("Incorrect password. Try again.");
  58.                             error++;
  59.                             count = 0;
  60.                             break;
  61.                         }
  62.                     }
  63.                 }
  64.             }
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement