Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.00 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 ConsoleApp1
  9. {
  10.     class Account
  11.     {
  12.  
  13.         public string Login { get; set; }
  14.         public string Password { get; set; }
  15.         public Account(string login, string password)
  16.         {
  17.             Login = login;
  18.             Password = password;
  19.         }
  20.         public Account()
  21.         {
  22.  
  23.         }
  24.  
  25.  
  26.         public void Register()
  27.         {
  28.             StreamWriter sW = new StreamWriter("C:\\accounts\\" + Login + ".txt");
  29.             sW.WriteLine(Password);
  30.             sW.Close();
  31.         }
  32.         public Account RegisterDisplay()
  33.         {
  34.             bool loopCheck = true;
  35.             string login = "";
  36.             string password = "";
  37.             while (loopCheck)
  38.             {
  39.                 Console.WriteLine("Podaj login");
  40.                 Console.Write("Login: ");
  41.                 login = Console.ReadLine();
  42.                 var fileInfo = new FileInfo("C:\\accounts\\" + login + ".txt");
  43.                 if (fileInfo.Exists)
  44.                 {
  45.                     Console.WriteLine("Konto z takim loginem juz istnieje, wybierz inny login");
  46.                 }
  47.                 else
  48.                 {
  49.                     loopCheck = false;
  50.                 }
  51.             }
  52.             Console.WriteLine("Podaj haslo");
  53.             Console.Write("Haslo: ");
  54.             password = Console.ReadLine();
  55.             var account = new Account(login, password);
  56.             return account;
  57.         }
  58.  
  59.         public bool LoginAccount()
  60.         {
  61.             string login = "";
  62.             string password = "";
  63.             bool loopCheckA = true;
  64.             bool loopCheckB = true;
  65.             bool returnType = true;
  66.             while (loopCheckA)
  67.             {
  68.                 Console.WriteLine("Podaj login");
  69.                 login = Console.ReadLine();
  70.                 var fileInfo = new FileInfo("C:\\accounts\\" + login + ".txt");
  71.                 if (fileInfo.Exists)
  72.                 {
  73.                     var sR = new StreamReader("C:\\accounts\\" + login + ".txt");
  74.                     while (loopCheckB)
  75.                     {
  76.                         Console.WriteLine("Podaj haslo");
  77.                         password = Console.ReadLine();
  78.                         if (password == sR.ReadLine())
  79.                         {
  80.                             Console.WriteLine("Haslo poprawne, zapraszam");
  81.                             loopCheckB = false;
  82.                         }
  83.                         else
  84.                         {
  85.                             Console.WriteLine("Podaj poprawne haslo");
  86.                         }
  87.                     }
  88.  
  89.                 loopCheckA = false;
  90.                 }
  91.                 else
  92.                 {
  93.                     Console.WriteLine("Nie ma takiego konta, sprobuj ponownie");
  94.                 }
  95.             }
  96.             return returnType;
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement