public static bool Login(string username, string password) { LoadSave(); foreach (var user in users) { if (user.Username.ToLower() == username.ToLower() && user.Password == GetHashCode(username.ToLower(), password)) { loggedInUser = user; return(true); } else if (user.Username.ToLower() == username.ToLower() && user.Password != GetHashCode(username.ToLower(), password)) { Menu.LoginText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("Wrong password!"); Console.ResetColor(); return(false); } } Menu.LoginText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("Account not found!"); Console.ResetColor(); return(false); }
public static bool CreateUser(string username, string password) { LoadSave(); var blackjackDB = dbClient.GetDatabase(dbName); var usersCol = blackjackDB.GetCollection <BsonDocument>("users"); foreach (var existingUser in users) { if (existingUser.Username.ToLower() == username.ToLower()) { return(false); } } SaveUser user = new SaveUser(); user.Username = username; user.Password = GetHashCode(username.ToLower(), password); user.Money = 300; string jsonData = JsonSerializer.Serialize(user); usersCol.InsertOne(BsonDocument.Parse(jsonData)); return(true); }