Exemple #1
0
        public static Guid AddUser(string accountName, string password, string email, bool locked, string[] roles, ref string msg)
        {
            if (Accounts.ContainsKey(accountName))
            {
                msg = "Account name already exists.";
                return(Guid.Empty);
            }

            AccountInfo ai = new AccountInfo();

            ai.AccountName = accountName;
            ai.AccountID   = Guid.NewGuid();
            ai.Email       = email;
            ai.Locked      = locked;
            ai.Password    = CryptoManager.GetSHA256Hash(password);
            ai.Roles       = new List <string>(roles);

            Accounts.Add(accountName, ai);

            if (CurrentPath.Length != 0)
            {
                SaveFile(CurrentPath);
            }
            return(ai.AccountID);
        }
Exemple #2
0
        public static bool Login(string accountName, string password, ref string msg)
        {
            AccountInfo ai = null;

            if (Accounts.Count == 0)
            {
                // Built in account only works when no other accounts have been specified
                if (accountName == "WispAdmin" && password == "wisp123")
                {
                    return(true);
                }

                msg = "Account doesn't exist.";
                return(false);
            }

            if (!Accounts.TryGetValue(accountName, out ai))
            {
                msg = "Account doesn't exist.";
                return(false);
            }

            string hashed = CryptoManager.GetSHA256Hash(password);

            if (hashed != ai.Password)
            {
                msg = "Account name / password combination doesn't exist.";
                return(false);
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// For clusters that don't use explicit characters, default characters are used for database tracking purposes.
        /// Call this method to get a reference to that default character.  Method will return null if App.Config's UseCharacters
        /// setting is TRUE
        /// </summary>
        /// <param name="owner"></param>
        /// <returns></returns>
        public ServerCharacterInfo GetOrCreateDefaultCharacter(bool isTempCharacter, ServerUser owner)
        {
            SqlConnection  con  = null;
            SqlTransaction tran = null;

            try
            {
                // This cluster doesn't use characters.  Create a default one for system purposes if we don't have one already
                ServerCharacterInfo ci = new ServerCharacterInfo();
                if (!DB.Instance.Character_LoadAny(owner.ID, ci)) // see if we can fetch the current default character from the DB.
                {
                    // Nope, couldn't find it. Try creating one.
                    ci = new ServerCharacterInfo(CreateNewCharacterShell(), owner);
                    ci.Properties.SetProperty((int)PropertyID.Name, "Mc_" + CryptoManager.GetSHA256Hash(owner.AccountName));

                    string msgCreate = "";
                    int    newCharId = NextCharId;

                    if (DB.Instance.Character_Create(owner.ID, ci.Stats, ci.Properties, (int)PropertyID.Name, ci.CharacterName, true, 1, isTempCharacter, out msgCreate, out tran, out con, out newCharId))
                    {
                        ci.CharacterInfo.ID = newCharId;
                        if (tran != null)
                        {
                            tran.Commit();
                        }
                        return(ci);
                    }
                    else
                    {
                        if (tran != null)
                        {
                            tran.Rollback();
                        }
                    }
                }
                else // got the default character
                {
                    return(ci);
                }
            }
            catch (Exception e)
            { }
            finally
            {
                if (con != null)
                {
                    con.Close();
                    con.Dispose();
                    con = null;
                }
                if (tran != null)
                {
                    tran.Dispose();
                    tran = null;
                }
            }

            return(null);
        }