Advertisement
Thewest123

Login

Sep 13th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.17 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.IO;
  7.  
  8. namespace _180913_Černý1
  9. {
  10.     class Program
  11.     {
  12.         static List<string> nickyList = new List<string>();
  13.         static List<string> heslaList = new List<string>();
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             Vytvorit();
  18.             NacistLoginy();
  19.             OvereniLoginu();
  20.         }
  21.  
  22.         static void Vytvorit()
  23.         {
  24.             if (!File.Exists("login.txt"))
  25.             {
  26.                 using (var sw = new StreamWriter("login.txt"))
  27.                 {
  28.                     sw.WriteLine("admin*admin");
  29.                 }
  30.             }
  31.         }
  32.  
  33.         static void NacistLoginy()
  34.         {
  35.             string[] radky = File.ReadAllLines("login.txt");
  36.  
  37.             nickyList.Clear();
  38.             heslaList.Clear();
  39.  
  40.             foreach (string radek in radky)
  41.             {
  42.                 int poziceHvezdicky = radek.IndexOf('*');
  43.  
  44.                 string nick = radek.Substring(0, poziceHvezdicky);
  45.                 string heslo = radek.Substring(poziceHvezdicky + 1);
  46.  
  47.                 nickyList.Add(nick);
  48.                 heslaList.Add(heslo);
  49.             }
  50.         }
  51.  
  52.         static void OvereniLoginu()
  53.         {
  54.             while (true)
  55.             {
  56.                 Console.WriteLine("Zalogujte se");
  57.                 Console.WriteLine("------------------------------------------");
  58.  
  59.                 Console.Write("Nick: ");
  60.                 string nick = Console.ReadLine();
  61.  
  62.                 Console.Write("Heslo: ");
  63.                 string heslo = Console.ReadLine();
  64.  
  65.                 if (nick != string.Empty && heslo != string.Empty)
  66.                 {
  67.                     if (!nick.Contains('*') && !heslo.Contains('*'))
  68.                     {
  69.                         if (nickyList.Contains(nick) &&  nickyList.IndexOf(nick) == heslaList.IndexOf(heslo))
  70.                         {
  71.                             Console.WriteLine("Tento nick a heslo existuje!");
  72.                             Menu();
  73.                             break;
  74.                         }
  75.                         else Console.WriteLine("Nesprávný nick nebo heslo!");
  76.                     }
  77.                     else Console.WriteLine("Nick a heslo nesmí obsahovat hvězdičku (*)!");
  78.                 }
  79.                 else Console.WriteLine("Nick a heslo nesmí být prázdné!");
  80.  
  81.                 Console.ReadLine();
  82.                 Console.Clear();
  83.             }
  84.         }
  85.  
  86.         private static void Menu()
  87.         {
  88.             while (true)
  89.             {
  90.                 Console.WriteLine("Menu:");
  91.                 Console.WriteLine("------------------------------------------");
  92.                 Console.WriteLine($"{"w",15} ~ výpis nicků");
  93.                 Console.WriteLine($"{"Ctrl + Alt + w",15} ~ výpis nicků a hesel");
  94.                 Console.WriteLine($"{"n",15} ~ nový login");
  95.                 Console.WriteLine($"{"k",15} ~ konec");
  96.                 Console.WriteLine("------------------------------------------");
  97.                 Console.Write("Co si přejete: ");
  98.  
  99.                 var cki = Console.ReadKey();
  100.                 Console.WriteLine();
  101.  
  102.                 if (cki.Key == ConsoleKey.W && cki.Modifiers == 0) VypisNicku();
  103.                 else if (cki.Key == ConsoleKey.W && cki.Modifiers == (ConsoleModifiers.Control | ConsoleModifiers.Alt)) VypisNickuAHesel();
  104.                 else if (cki.Key == ConsoleKey.N && cki.Modifiers == 0) NovyLogin();
  105.                 else if (cki.Key == ConsoleKey.K && cki.Modifiers == 0) break;
  106.                 else Console.WriteLine($"{cki.Modifiers} + {cki.Key} ~ {cki.KeyChar} >> Neexistuje!");
  107.             }
  108.         }
  109.  
  110.         static void VypisNicku()
  111.         {
  112.             NacistLoginy();
  113.  
  114.             Console.ForegroundColor = ConsoleColor.Green;
  115.  
  116.             Console.WriteLine($"*-----*-------------------------*");
  117.             Console.WriteLine($"*{"Číslo",5}|{"Nick",-25}|");
  118.             Console.WriteLine($"*-----*-------------------------*");
  119.             for (int i = 0; i < nickyList.Count; i++)
  120.             {                
  121.                 Console.WriteLine($"|{i+1,5:00}|{nickyList[i],-25}|");
  122.             }
  123.             Console.WriteLine($"*-----*-------------------------*");
  124.  
  125.             Console.ResetColor();
  126.         }
  127.  
  128.         static void VypisNickuAHesel()
  129.         {
  130.             NacistLoginy();
  131.  
  132.             Console.ForegroundColor = ConsoleColor.Green;
  133.  
  134.             Console.WriteLine($"*-----*-------------------------*-------------------------*");
  135.             Console.WriteLine($"|{"Číslo",5}|{"Nick",-25}|{"Heslo",-25}*");
  136.             Console.WriteLine($"*-----*-------------------------*-------------------------*");
  137.             for (int i = 0; i < nickyList.Count; i++)
  138.             {
  139.                 Console.WriteLine($"|{i+1,5:00}|{nickyList[i],-25}|{heslaList[i],-25}|");
  140.             }
  141.             Console.WriteLine($"*-----*-------------------------*-------------------------*");
  142.  
  143.             Console.ResetColor();
  144.         }
  145.  
  146.         static void NovyLogin()
  147.         {
  148.             Console.WriteLine("Zadejte:");
  149.             Console.WriteLine("------------------------------------------");
  150.  
  151.             Console.Write("Nick: ");
  152.             string nick = Console.ReadLine();
  153.  
  154.             Console.Write("Heslo: ");
  155.             string heslo = Console.ReadLine();
  156.  
  157.             if (nick != string.Empty && heslo != string.Empty)
  158.             {
  159.                 if (!nick.Contains('*') && !heslo.Contains('*'))
  160.                 {
  161.                     if (!nickyList.Contains(nick))
  162.                     {
  163.                         using (var sw = new StreamWriter("login.txt", true))
  164.                         {
  165.                             sw.WriteLine($"{nick}*{heslo}");
  166.                         }
  167.                     }
  168.                     else Console.WriteLine("Zadaný nick již v souboru existuje!");
  169.                 }
  170.                 else Console.WriteLine("Nick a heslo nesmí obsahovat hvězdičku (*)!");
  171.             }
  172.             else Console.WriteLine("Nick a heslo nesmí být prázdné!");
  173.         }
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement