StoimenK

C# 2.5 Login

Jan 23rd, 2020
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _2._5_Login
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             /* Input: string
  14.                Password will be reversed user name +++
  15.                Until you receive the correct password print on the console “Incorrect password. Try again.”.    +++
  16.                When you receive the correct password print “User {username} logged in.” +++
  17.                However on the fourth try if the password is still not correct print “User {username} blocked!” and end the program. +++ */
  18.  
  19.             string userName = Console.ReadLine();
  20.  
  21.             string password = string.Empty;
  22.            
  23.  
  24.             for (int i = userName.Length -1; i >= 0; i--)
  25.             {
  26.                 password += userName[i];
  27.             }
  28.  
  29.             for (int i = 1; i <= 4; i++)
  30.             {
  31.                 string correctPas = Console.ReadLine();
  32.  
  33.                 if (password == correctPas)
  34.                 {
  35.                     Console.WriteLine($"User {userName} logged in.");
  36.                     break;
  37.                 }
  38.                 if (i <= 3)
  39.                 {
  40.                     Console.WriteLine("Incorrect password. Try again.");
  41.                 }
  42.                 else
  43.                 {
  44.                     Console.WriteLine($"User {userName} blocked!");
  45.                 }
  46.             }
  47.            
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment