public bool AuthenticateUser(IUser user, UserDataBase userDataBase) { if (string.IsNullOrEmpty(user.Name)) { return(LoginCheck(user.Email, user.Password, userDataBase)); } else { return(LoginCheck(user.Name, user.Password, userDataBase)); } }
public IUser Search(string name, UserDataBase userDataBase) { foreach (var item in UsersList) { if (item.Name == name) { return(item); } } return(null); }
public void Add(IUser user, UserDataBase userDataBase) { if (disposed) { throw new ObjectDisposedException("UserDataBase"); } Authenticator authenticator = new Authenticator(); if (authenticator.AuthenticateUser(user, userDataBase)) { UsersList.Add(user); } else { Console.WriteLine("This username exists"); } }
static void Main(string[] args) { UserDataBase userDataBase = new UserDataBase(); while (true) { Console.WriteLine("Input Login: "******"exit") { break; } Console.WriteLine("Input Password: "); var password = Console.ReadLine(); User user = new User(login, password); userDataBase.Add(user, userDataBase); } userDataBase.Dispose(); }
private bool LoginCheck(MailAddress email, string password, UserDataBase userDataBase) { foreach (var item in userDataBase.UsersList) { if (item.Email.Address == email.Address) { if (item.Password == password) { Console.WriteLine(item.Time); item.Time = DateTime.Now; return(false); } else { Console.WriteLine("Password is incorrect"); return(false); } } } return(true); }