/// <summary> /// Stores a password as a salted hash in a factions AuthDB. /// </summary> /// <param name="game"></param> /// <param name="factionEntity"></param> /// <param name="password"></param> public static void StorePasswordAsHash(Game game, Entity factionEntity, string password) { //Entity factionEntity = game.GlobalManager.GetEntityByGuid(factionGuid); AuthDB authDB = factionEntity.GetDataBlob <AuthDB>(); authDB.Hash = CreateHash(password); }
/// <summary> /// Validates a password given a hash of the correct one. /// </summary> /// <param name="factionEntity">the factionEntity</param> /// <param name="password">The password to check.</param> public static bool Validate(Entity factionEntity, string password) { AuthDB authDB = factionEntity.GetDataBlob <AuthDB>(); // Extract the parameters from the hash char[] delimiter = { ':' }; string[] split = authDB.Hash.Split(delimiter); int iterations = Int32.Parse(split[ITERATION_INDEX]); byte[] salt = Convert.FromBase64String(split[SALT_INDEX]); byte[] hash = Convert.FromBase64String(split[PBKDF2_INDEX]); byte[] testHash = PBKDF2(password, salt, iterations, hash.Length); return(SlowEquals(hash, testHash)); }
internal void CreateGame(NewGameOptionsVM options) { StatusText = "Creating Game..."; // TODO: Databind the GameSettings object in the NewGameOptionsVM var gameSettings = new NewGameSettings { GameName = "Test Game", MaxSystems = options.NumberOfSystems, SMPassword = options.GmPassword, DataSets = options.SelectedModList.Select(dvi => dvi.Directory), CreatePlayerFaction = options.CreatePlayerFaction, DefaultFactionName = options.FactionName, DefaultPlayerPassword = options.FactionPassword, DefaultSolStart = options.DefaultStart, }; Game = new Game(gameSettings); // TODO: Select default player more reliably CurrentPlayer = Game.Players[0]; CurrentAuthToken = new AuthenticationToken(CurrentPlayer, options.FactionPassword); ReadOnlyDictionary <Entity, AccessRole> roles = CurrentPlayer.GetAccessRoles(CurrentAuthToken); CurrentFaction = roles.FirstOrDefault(role => (role.Value & AccessRole.Owner) != 0).Key; SetFactionData(); var auth = new AuthDB(); CurrentFaction.SetDataBlob(auth); AuthProcessor.StorePasswordAsHash(Game, CurrentFaction, options.FactionPassword); StatusText = "Game Created."; StarSystemSelectionViewModel = new StarSystemSelectionVM(this, Game, CurrentFaction); StarSystemSelectionViewModel.Initialise(); }
public AuthDB(AuthDB db) { Hash = db.Hash; }