Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 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 LoginSystem
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             Console.WriteLine("This is a protected system. Unautherized access is strictly prohibited. Please login or exit.\n");
  15.  
  16.             bool loggedIn = false;
  17.  
  18.             while (loggedIn == false)
  19.             {
  20.  
  21.                 loggedIn = Verification.Login();
  22.  
  23.             }
  24.  
  25.             Console.ReadKey();
  26.  
  27.         }
  28.     }
  29. }
  30.  
  31.  
  32. class Database
  33. {
  34.  
  35.     public static LoginSystem.LoginSystems db = new LoginSystem.LoginSystems();
  36.  
  37.     public static void AddUser(string username, string password)
  38.     {
  39.             LoginSystem.User NewUser = new LoginSystem.User();
  40.             NewUser.Username = username;
  41.             NewUser.Password = password;
  42.             NewUser.LastLogin = System.DateTime.Now;
  43.  
  44.             db.Users.Add(NewUser);
  45.             db.SaveChanges();
  46.     }
  47.  
  48.     public static bool CheckLogin(string username, string password)
  49.     {
  50.  
  51.         foreach (var User in db.Users)
  52.         {
  53.  
  54.             if (User.Username == username && User.Password == password)
  55.             {
  56.                 Console.WriteLine("\nYou have been successfully logged in.");
  57.                 return true;
  58.  
  59.             } else {
  60.  
  61.                 Console.WriteLine("\nYour username/password is incorrect. Please try again.");
  62.                 return false;
  63.             }
  64.         }
  65.         return false;
  66.     }
  67.  
  68. }
  69.  
  70.  
  71. class Verification
  72. {
  73.  
  74.     public static bool Login()
  75.     {
  76.         Console.Write("Username:"); string username = Console.ReadLine();
  77.         Console.Write("Password:"); string password = Console.ReadLine();
  78.  
  79.         bool LoginCheck = Database.CheckLogin(username, password);
  80.  
  81.         return LoginCheck;
  82.     }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement