Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- string sPassword = "12345";
- string sSecretMessage = "Секретное сообщение: ******** ********** ***************** *** *******.";
- string sUserEnter = "";
- int iCounter = 5;
- int iPasswordPosition = 16;
- string s = "";
- Console.Title = "2.8 Пароль";
- string sMessage = "Введите пароль: ";
- while (iCounter > 0 && sUserEnter != sPassword)
- {
- Console.Write(sMessage);
- while (true)
- {
- ConsoleKeyInfo c = Console.ReadKey();
- if (c.Key == ConsoleKey.Enter)
- break;
- s += c.KeyChar;
- Console.SetCursorPosition(iPasswordPosition, 0);
- foreach (char ch in s)
- Console.Write('*');
- }
- sUserEnter = s;
- s = "";
- sMessage = $"Введите пароль (осталось попыток {--iCounter}): ";
- iPasswordPosition = 37;
- Console.Clear();
- }
- if (sUserEnter != sPassword)
- {
- sSecretMessage = "Пароль неверен";
- }
- Console.WriteLine(sSecretMessage);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement