Advertisement
raziel13

basic_syntax_ex_ex_05_login

Dec 4th, 2018
147
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.  
  3. namespace _05_login
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)//100/100
  8.         {
  9.             string userName = Console.ReadLine();//username
  10.             char[] correctPasswordChars = new char[userName.Length];//count username characters
  11.  
  12.             for (int i = 0; i < userName.Length; i++)//loop with count characters of username
  13.             {
  14.                 correctPasswordChars[i] = userName[(userName.Length - 1) - i]; //reverse username characters
  15.             }
  16.             string correctPassword = new string(correctPasswordChars); //generate correct password
  17.  
  18.             for (int i = 0; i < 4; i++)
  19.             {
  20.                 string password = Console.ReadLine();
  21.                 if (password == correctPassword)
  22.                 {
  23.                     Console.WriteLine($"User {userName} logged in.");
  24.                     break;
  25.                 }
  26.                 else if (i >= 3)
  27.                 {
  28.                     Console.WriteLine($"User {userName} blocked!");
  29.                 }
  30.                 else
  31.                 {
  32.                     Console.WriteLine("Incorrect password. Try again.");
  33.                 }
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement