Advertisement
lastmusician

2.3

Mar 12th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.81 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. using System.Drawing;
  7.  
  8. namespace Csharp_light
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string userName = "", userLogin = "", userPassword = "",dbPassword = "";
  15.             bool enter = false, exit = false;
  16.  
  17.             Console.WriteLine("Команды:\nSetName - установить имя\nSetLogin - дать логин\nSetPassword - дать пароль\nLogAll - вывести всю информацию\nChangeConsoleColor -изменить цвет консоли\nLogDB - вывести пароль в рамке\nEsc - завершить программу");
  18.  
  19.             while (!exit)
  20.             {
  21.                 string option = Console.ReadLine();
  22.  
  23.                 switch (option)
  24.                 {
  25.                     case "SetName":
  26.                         Console.Write("Введите ваше Имя:\nВас зовут ");
  27.                         userName = Console.ReadLine();
  28.                         break;
  29.                     case "SetLogin":
  30.                         Console.Write("Введите логин:\nВаш логин ");
  31.                         userLogin = Console.ReadLine();
  32.                         break;
  33.                     case "SetPassword":
  34.                         dbPassword = userPassword;
  35.                         Console.Write("Введите пароль:");
  36.                         while (!enter)
  37.                         {
  38.                             ConsoleKeyInfo charKey = Console.ReadKey(true);
  39.  
  40.                             switch (charKey.Key)
  41.                             {
  42.                                 case ConsoleKey.Enter:
  43.                                     Console.Write('\n');
  44.                                     enter = true;
  45.                                     break;
  46.                                 case ConsoleKey.Backspace:
  47.                                     if (userPassword.Length != 0)
  48.                                     {
  49.                                         userPassword = userPassword.Remove(userPassword.Length - 1);
  50.                                         Console.Write("\b \b");
  51.                                     }
  52.                                     break;
  53.                                 default:
  54.                                     userPassword += charKey.KeyChar;
  55.                                     Console.Write("*");
  56.                                     break;
  57.                             }
  58.                         }
  59.                         break;
  60.                     case "LogAll":
  61.                         if (userPassword.Length > 0)
  62.                         {
  63.                             Console.WriteLine("Вас зовут: " + userName + " ваш логин: " + userLogin);
  64.                         }
  65.                         else
  66.                         {
  67.                             Console.WriteLine("Вам нужно задать пароль");
  68.                         }
  69.                         break;
  70.                     case "ChangeConsoleColor":
  71.                         Console.WriteLine("Введите цвет: red, blue, white");
  72.                         string color = Console.ReadLine();
  73.                         switch (color)
  74.                         {
  75.                             case "red":
  76.                                 Console.ForegroundColor = ConsoleColor.Red;
  77.                                 break;
  78.                             case "blue":
  79.                                 Console.ForegroundColor = ConsoleColor.Blue;
  80.                                 break;
  81.                             case "white":
  82.                                 Console.ForegroundColor = ConsoleColor.White;
  83.                                 break;
  84.                         }
  85.                                 break;
  86.                     case "LogDB":
  87.                         if (userPassword == dbPassword)
  88.                         {
  89.                             Console.WriteLine("Установите пароль");
  90.                         }
  91.                         else
  92.                         {
  93.                            
  94.                             string line = "";
  95.                             for (int i = 0; i < userPassword.Length + 2; i++)
  96.                             {
  97.                                 line += '#';
  98.                             }
  99.                             Console.WriteLine(line);
  100.                             Console.WriteLine("#" + userPassword + "#");
  101.                             Console.WriteLine(line);
  102.                         }
  103.                         break;
  104.                     case "Esc":
  105.                         exit = true;
  106.                         break;
  107.                        
  108.                 }
  109.             }
  110.         }
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement