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 LoginSystem
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("This is a protected system. Unautherized access is strictly prohibited. Please login or exit.\n");
- bool loggedIn = false;
- while (loggedIn == false)
- {
- loggedIn = Verification.Login();
- }
- Console.ReadKey();
- }
- }
- }
- class Database
- {
- public static LoginSystem.LoginSystems db = new LoginSystem.LoginSystems();
- public static void AddUser(string username, string password)
- {
- LoginSystem.User NewUser = new LoginSystem.User();
- NewUser.Username = username;
- NewUser.Password = password;
- NewUser.LastLogin = System.DateTime.Now;
- db.Users.Add(NewUser);
- db.SaveChanges();
- }
- public static bool CheckLogin(string username, string password)
- {
- foreach (var User in db.Users)
- {
- if (User.Username == username && User.Password == password)
- {
- Console.WriteLine("\nYou have been successfully logged in.");
- return true;
- } else {
- Console.WriteLine("\nYour username/password is incorrect. Please try again.");
- return false;
- }
- }
- return false;
- }
- }
- class Verification
- {
- public static bool Login()
- {
- Console.Write("Username:"); string username = Console.ReadLine();
- Console.Write("Password:"); string password = Console.ReadLine();
- bool LoginCheck = Database.CheckLogin(username, password);
- return LoginCheck;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement