SaNik74

password-protected program

Feb 18th, 2023 (edited)
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. internal class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         const string SecretMessage = "Теперь ты знаешь секрет ˆ_ˆ";
  6.         const string Password = "1234";
  7.         int inputAttemps = 3;
  8.         string? userInput = "";
  9.  
  10.         for (int i = inputAttemps; i > 0; i--)
  11.         {
  12.             Console.Write("Введите пароль: ");
  13.             userInput = Console.ReadLine();
  14.             --inputAttemps;
  15.  
  16.             if (userInput != Password)
  17.             {
  18.                 Console.WriteLine("Пароль введень неверно.");
  19.                 Console.WriteLine($"Осталось {inputAttemps} попыток.\n" +
  20.                     $"Нажмите на любую клавишу...");
  21.                 Console.ReadKey();
  22.                 Console.Clear();
  23.             }
  24.             else if (userInput == Password)
  25.             {
  26.                 Console.Clear();
  27.                 Console.WriteLine(SecretMessage);
  28.                 Console.ReadKey();
  29.                 break;
  30.             }
  31.         }
  32.         if (userInput != Password)
  33.         {
  34.             Console.WriteLine("Исчерпан лимит попыток.\nТы не узнал секрет.");
  35.             Console.ReadKey();
  36.             Console.Clear();
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment