/// <summary> /// Retrieve the info of a specific player /// in the form of a BSonDocument /// (Used for logged in player) /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> public static BsonDocument getSpecificPlayer(string username, string password) { var player = getAllUsersCollection().FindOne(Query.EQ("pl_username", username)); return(player["pl_password"]. Equals(PasswordHashAndSalt.GenerateSaltedHash(PasswordHashAndSalt.getBytes(password), player["pl_passwordSalt"].AsByteArray)) ? player: null); }
/// <summary> /// Save the information of a new player /// </summary> /// <param name="username">Their username</param> /// <param name="password">Their password (Hashed and salted in method)</param> public static void addNewPlayer(string username, string password) { byte[] salt = PasswordHashAndSalt.CreateSalt(); var player = new BsonDocument { { "_id", getUnusedID() }, { "pl_username", username }, { "pl_usernameLower", username.ToLower() }, { "pl_password", PasswordHashAndSalt.GenerateSaltedHash(PasswordHashAndSalt.getBytes(password), salt) }, { "pl_passwordSalt", salt }, { "pl_joinDate", DateTime.Today.ToString("dd.MM.yyyy") }, { "pl_records", new BsonArray { createPlayerRecord(1, "Registered for the game.") } } }; getAllUsersCollection().Insert(player); }