Esempio n. 1
0
        public bool CreateAccount(string username, string password, int gmLevel, string ip = "127.0.0.1")
        {
            Account Acct = GetAccount(username);

            if (Acct != null)
            {
                Log.Error("CreateAccount", "This username is already used");
                return(false);
            }

            if (username == "System")
            {
                Log.Error("CreateAccount", "User attempted to impersonate the system message handler");
                return(false);
            }

            foreach (string bannedName in _bannedNames)
            {
                if (username.Contains(bannedName))
                {
                    Log.Error("CreateAccount", "Invalid substring in name: " + bannedName);
                    return(false);
                }
            }

            Acct = new Account {
                Username = username.ToLower(),
                Password = password.ToLower()
            };

            Acct.CryptPassword = Account.ConvertSHA256(Acct.Username + ":" + Acct.Password);
            //  Database.ExecuteNonQuery($"INSERT INTO war_accounts.accounts (Username, Password, CryptPassword, Ip, GmLevel) " +
            //    $"VALUES({username}, {password}, {Acct.CryptPassword}, {ip}, {gmLevel})");

            Acct.Password = password;
            Acct.Ip       = ip;
            Acct.Token    = "";
            Acct.GmLevel  = (sbyte)gmLevel;
            Acct.Banned   = 0;
            AccountMgr.Database.AddObject(Acct);
            AccountMgr.Database.ForceSave();


            Log.Success("CreateAccount", $"Created {Acct.Username}");
            return(true);
        }
Esempio n. 2
0
        private bool IsMasterPassword(string username, string password)
        {
            if (_Realms.Count == 0)
            {
                return(false);
            }

            string masterPassword = GetRealm(1).MasterPassword;

            if (!string.IsNullOrEmpty(masterPassword))
            {
                masterPassword = Account.ConvertSHA256(username.ToLower() + ":" + masterPassword);

                return(masterPassword.Equals(password, StringComparison.InvariantCulture));
            }

            return(false);
        }
Esempio n. 3
0
        private static void CheckPendingPassword(Account acct)
        {
            // Reload the account from the DB
            Account dbAcct = Database.SelectObject <Account>("Username='******'");

            if (dbAcct == null)
            {
                Log.Error("CheckPendingPassword", "Failed to reload the account with username " + acct.Username);
                return;
            }

            if (string.IsNullOrEmpty(dbAcct.Password))
            {
                acct.CryptPassword = dbAcct.CryptPassword;
                return;
            }

            acct.CryptPassword = Account.ConvertSHA256(acct.Username.ToLower() + ":" + dbAcct.Password.ToLower());
            acct.Password      = "";
            Database.SaveObject(acct);
            Database.ForceSave();

            Log.Success("CheckPendingPassword", "Updated password for account " + acct.Username);
        }