public UserSettings CreateAndReturnUser(UserSettings userSettings) { DatabaseUser dbUser = new DatabaseUser(userSettings); dbUser.Salt = UserPasswordTools.GenerateRandomPasswordSalt(); dbUser.Password = UserPasswordTools.HashAndSaltPassword(userSettings.Password, dbUser.Salt); dbUser.EscapeStringFields(); if (_dbQueryService.PersistNewUser(dbUser)) { UserSettings createdUser = GetUserByUsername(userSettings.Username); createdUser.CreateAPIKey = userSettings.CreateAPIKey; if (createdUser.CreateAPIKey) { createdUser.APIKey = _apiKeyService.RegisterNewAPIKey(createdUser.UserId); } return(createdUser); } return(null); }