Advertisement
Guest User

2.8

a guest
May 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 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 ConsoleApp2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string sPassword = "12345";
  14.             string sSecretMessage = "Секретное сообщение: ******** ********** ***************** *** *******.";
  15.             string sUserEnter = "";
  16.             int iCounter = 5;
  17.             int iPasswordPosition = 16;
  18.             string s = "";
  19.             Console.Title = "2.8 Пароль";
  20.             string sMessage = "Введите пароль: ";
  21.  
  22.             while (iCounter > 0 && sUserEnter != sPassword)
  23.             {
  24.                 Console.Write(sMessage);
  25.  
  26.                 while (true)
  27.                 {
  28.                     ConsoleKeyInfo c = Console.ReadKey();
  29.                     if (c.Key == ConsoleKey.Enter)
  30.                         break;
  31.                     s += c.KeyChar;
  32.                     Console.SetCursorPosition(iPasswordPosition, 0);
  33.                     foreach (char ch in s)
  34.                         Console.Write('*');
  35.                 }
  36.  
  37.                 sUserEnter = s;
  38.                 s = "";
  39.                 sMessage = $"Введите пароль (осталось попыток {--iCounter}): ";
  40.                 iPasswordPosition = 37;
  41.                 Console.Clear();
  42.             }
  43.  
  44.             if (sUserEnter != sPassword)
  45.             {
  46.                 sSecretMessage = "Пароль неверен";
  47.             }
  48.  
  49.             Console.WriteLine(sSecretMessage);
  50.             Console.ReadKey();
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement