示例#1
0
        public static Account CreateAccount(string email, string password, string battleTag, Account.UserLevels userLevel = Account.UserLevels.User)
        {
            if (password.Length > 16)
            {
                password = password.Substring(0, 16);                       // make sure the password does not exceed 16 chars.
            }
            var hashCode         = GetRandomHashCodeForBattleTag();
            var salt             = SRP6a.GetRandomBytes(32);
            var passwordVerifier = SRP6a.CalculatePasswordVerifierForAccount(email, password, salt);


            var newDBAccount = new DBAccount
            {
                Email            = email,
                Salt             = salt,
                PasswordVerifier = passwordVerifier,
                BattleTagName    = battleTag,
                UserLevel        = userLevel,
                HashCode         = hashCode
            };


            DBSessions.AccountSession.SaveOrUpdate(newDBAccount);
            DBSessions.AccountSession.Flush();

            return(GetAccountByDBAccount(newDBAccount));
        }
示例#2
0
        public Account(string email, string password, UserLevels userLevel) // Account with **newly generated** persistent ID
            : base()
        {
            if (password.Length > 16)
            {
                password = password.Substring(0, 16);                       // make sure the password does not exceed 16 chars.
            }
            var salt             = SRP6a.GetRandomBytes(32);
            var passwordVerifier = SRP6a.CalculatePasswordVerifierForAccount(email, password, salt);

            this.SetFields(email, salt, passwordVerifier, userLevel);
        }
示例#3
0
        public Account(string email, string password, string battleTagName, int hashCode, UserLevels userLevel) // Account with **newly generated** persistent ID
            : base(StringHashHelper.HashIdentity(battleTagName + "#" + hashCode.ToString("D4")))
        {
            if (password.Length > 16)
            {
                password = password.Substring(0, 16);                       // make sure the password does not exceed 16 chars.
            }
            var salt             = SRP6a.GetRandomBytes(32);
            var passwordVerifier = SRP6a.CalculatePasswordVerifierForAccount(email, password, salt);

            this.SetFields(email, salt, passwordVerifier, battleTagName, hashCode, userLevel);
        }
示例#4
0
 public static bool UpdatePassword(this Account account, string newPassword)
 {
     account.PasswordVerifier = SRP6a.CalculatePasswordVerifierForAccount(account.Email, newPassword, account.Salt);
     try
     {
         SaveToDB(account);
         return(true);
     }
     catch (Exception e)
     {
         Logger.ErrorException(e, "UpdatePassword()");
         return(false);
     }
 }
示例#5
0
        public bool VerifyPassword(string password)
        {
            if (string.IsNullOrEmpty(password))
            {
                return(false);
            }

            if (password.Length < 8 || password.Length > 16)
            {
                return(false);
            }

            var calculatedVerifier = SRP6a.CalculatePasswordVerifierForAccount(this.Email, password, this.Salt);

            return(calculatedVerifier.SequenceEqual(this.PasswordVerifier));
        }
示例#6
0
        public void UpdatePassword(string newPassword)
        {
            this.PasswordVerifier = SRP6a.CalculatePasswordVerifierForAccount(this.Email, newPassword, this.Salt);
            try
            {
                var query = string.Format("UPDATE accounts SET passwordVerifier=@passwordVerifier WHERE id={0}", this.PersistentID);

                using (var cmd = new SQLiteCommand(query, DBManager.Connection))
                {
                    cmd.Parameters.Add("@passwordVerifier", System.Data.DbType.Binary, 128).Value = this.PasswordVerifier;
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                Logger.ErrorException(e, "UpdatePassword()");
            }
        }