/// <summary>
        /// Sets the password for a user. Password is saved as an md5 hash
        /// </summary>
        /// <returns><c>true</c>, if password was set, <c>false</c> otherwise.</returns>
        /// <param name="principalID">Principal identifier.</param>
        /// <param name="authType">Auth type.</param>
        /// <param name="password">Password.</param>
        public virtual bool SetPassword (UUID principalID, string authType, string password)
        {
            string passwordSalt = Util.Md5Hash (UUID.Random ().ToString ());
            string md5PasswdHash = Util.Md5Hash (Util.Md5Hash (password) + ":" + passwordSalt);

            AuthData auth = m_Database.Get (principalID, authType);
            if (auth == null) {
                auth = new AuthData { PrincipalID = principalID, AccountType = authType };
            }
            auth.PasswordHash = md5PasswdHash;
            auth.PasswordSalt = passwordSalt;
            return SaveAuth (auth, principalID);
        }
        public AuthData Get (UUID principalID, string authType)
        {
            QueryFilter filter = new QueryFilter ();
            filter.andFilters ["UUID"] = principalID;
            filter.andFilters ["accountType"] = authType;
            List<string> query = GD.Query (new string [] { "*" }, m_realm, filter, null, null, null);
            AuthData data = null;
            for (int i = 0; i < query.Count; i += 5) {
                data = new AuthData {
                    PrincipalID = UUID.Parse (query [i]),
                    PasswordHash = query [i + 1],
                    PasswordSalt = query [i + 2],
                    AccountType = query [i + 3]
                };
            }

            return data;
        }
        public virtual bool SetPassword(UUID principalID, string authType, string password)
        {
            string passwordSalt = Util.Md5Hash(UUID.Random().ToString());
            string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + passwordSalt);

            AuthData auth = m_Database.Get(principalID, authType);
            if (auth == null)
            {
                auth = new AuthData {PrincipalID = principalID, AccountType = authType};
            }
            auth.PasswordHash = md5PasswdHash;
            auth.PasswordSalt = passwordSalt;
            if (!m_Database.Store(auth))
            {
                MainConsole.Instance.DebugFormat("[AUTHENTICATION DB]: Failed to store authentication data");
                return false;
            }

            MainConsole.Instance.InfoFormat("[AUTHENTICATION DB]: Set password for principalID {0}", principalID);
            return true;
        }
 public bool Store(AuthData data)
 {
     QueryFilter filter = new QueryFilter();
     filter.andFilters["UUID"] = data.PrincipalID;
     filter.andFilters["accountType"] = data.AccountType;
     GD.Delete(m_realm, filter);
     Dictionary<string, object> row = new Dictionary<string, object>(4);
     row["UUID"] = data.PrincipalID;
     row["passwordHash"] = data.PasswordHash;
     row["passwordSalt"] = data.PasswordSalt;
     row["accountType"] = data.AccountType;
     return GD.Insert(m_realm, row);
 }
        bool SaveAuth (AuthData auth, UUID principalID)
        {
            if (!m_Database.Store (auth)) {
                MainConsole.Instance.DebugFormat ("[Authentication DB]: Failed to store authentication data");
                return false;
            }

            MainConsole.Instance.InfoFormat ("[Authentication DB]: Set password for principalID {0}", principalID);
            return true;

        }
 public virtual bool SetSaltedPassword (UUID principalID, string authType, string salt, string pass)
 {
     AuthData auth = m_Database.Get (principalID, authType);
     if (auth == null) {
         auth = new AuthData { PrincipalID = principalID, AccountType = authType };
     }
     auth.PasswordHash = pass;
     auth.PasswordSalt = salt;
     return SaveAuth (auth, principalID);
 }
        public virtual bool SetPlainPassword(UUID principalID, string authType, string pass)
        {
            AuthData auth = m_Database.Get(principalID, authType);
            if (auth == null)
            {
                auth = new AuthData {PrincipalID = principalID, AccountType = authType};
            }
            auth.PasswordHash = pass;
            auth.PasswordSalt = "";
            if (!m_Database.Store(auth))
            {
                MainConsole.Instance.DebugFormat("[AUTHENTICATION DB]: Failed to store authentication data");
                return false;
            }

            MainConsole.Instance.InfoFormat("[AUTHENTICATION DB]: Set password for principalID {0}", principalID);
            return true;
        }