コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: rbua/Checkers
        private void SaveMenuItem_Click(object sender, RoutedEventArgs e)
        {
            Game game = GameManager.Game;

            if (!game.GameOver)
            {
                GameModel model = new GameModel
                {
                    Player2     = game.Player2,
                    Player1     = game.Player1,
                    Cells       = GameModel.GetCurrentCells(),
                    DateCreated = DateTime.Now
                };

                var storeModel = new GameModelStoreModel
                {
                    GameModelModel = JsonConvert.SerializeObject(model, Formatting.Indented),
                    DateCreated    = DateTime.Now
                };

                var context = new GameModelContext(@"Data Source=.\SQLEXPRESS;Initial Catalog=Players;Integrated Security=True");
                context.GameModels.Add(storeModel);
                context.SaveChanges();

                MessageBox.Show("Successfully saved");
            }
        }
コード例 #2
0
        public Guid CreateUserAccount([FromBody] CreateUserAccountDTO createUserAccountDTO)
        {
            byte[] salt = new byte[128 / 8];

            using (var rng = RandomNumberGenerator.Create())
            {
                rng.GetBytes(salt);
            }

            string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                                                       password: createUserAccountDTO.Password,
                                                       salt: salt,
                                                       prf: KeyDerivationPrf.HMACSHA1,
                                                       iterationCount: 10000,
                                                       numBytesRequested: 256 / 8));

            var userAccount = new UserAccount
            {
                Name  = createUserAccountDTO.Name,
                Email = createUserAccountDTO.Email,
                UserAccountAuthentication = new UserAccountAuthentication
                {
                    EncryptedPassword = hashed,
                    PasswordSalt      = Convert.ToBase64String(salt)
                }
            };

            _context.UserAccounts.Add(userAccount);
            _context.SaveChanges();

            return(userAccount.Id);
        }