Пример #1
0
        public static Account Create(string username, string password)
        {
            var passwordSalt = new byte[64];
            new RNGCryptoServiceProvider().GetBytes(passwordSalt);
            var passwordHash =
                SHA512.Create().ComputeHash(Encoding.Unicode.GetBytes(password).Concat(passwordSalt).ToArray());
            var account = new Account
            {
                Username = username,
                Salt = passwordSalt,
                Password = passwordHash,
                Banned = false,
                Created = DateTime.Now,
                Characters = new List<string>(4),
                SelectedCharacter = null
            };

            return account;
        }
Пример #2
0
 /// <summary>
 ///     Updates the data of an existing account. (Maybe you want to change the password, or add/remove users, or ban/unban
 ///     the account?)
 /// </summary>
 /// <param name="account">The account to update.</param>
 public void UpdateAccount(Account account)
 {
     using (var transaction = Session.BeginTransaction())
     {
         Session.SaveOrUpdate(account);
         transaction.Commit();
     }
 }
Пример #3
0
        /// <summary>
        ///     Deletes the specified account.
        /// </summary>
        /// <param name="account">The account to delete.</param>
        public void DeleteAccount(Account account)
        {
            // Delete its characters
            foreach (var character in account.Characters)
            {
                if (!CharacterExists(character)) continue; // Maybe this character was deleted by error, or otherwise?
                DeleteCharacter(GetCharacter(character));
            }

            using (var transaction = Session.BeginTransaction())
            {
                Session.Delete(account);
                transaction.Commit();
            }
        }