Beispiel #1
0
        private UserAccount Authenticate(string firstName, string lastName, string password, out UUID token)
        {
            UserAccount accountInfo = m_UserAccountService[firstName, lastName];

            token = m_AuthInfoService.Authenticate(UUID.Zero, accountInfo.Principal.ID, password, 30);

            return(accountInfo);
        }
        public bool Run()
        {
            m_Log.Info("Testing that we get no data");
            UserAuthInfo authInfo;
            UserAuthInfo checkAuthInfo;

            try
            {
                authInfo = m_AuthInfoServiceBackend[m_UserID];
                return(false);
            }
            catch (KeyNotFoundException)
            {
                /* this happens here */
            }

            m_Log.Info("Testing predefined Auth Info");
            authInfo = new UserAuthInfo()
            {
                ID           = m_UserID,
                PasswordHash = "fd6224f938c9c333dfbeb2336c6640e7",
                PasswordSalt = "f5a7924e621e84c9280a9a27e1bcb7f6"
            };

            m_Log.InfoFormat("Hash={0} Salt={1}", authInfo.PasswordHash, authInfo.PasswordSalt);

            m_AuthInfoServiceBackend.Store(authInfo);

            m_Log.Info("Retrieving auth info");
            try
            {
                checkAuthInfo = m_AuthInfoServiceBackend[m_UserID];
            }
            catch
            {
                return(false);
            }

            m_Log.InfoFormat("Hash={0} Salt={1}", checkAuthInfo.PasswordHash, checkAuthInfo.PasswordSalt);

            if (checkAuthInfo.ID != authInfo.ID ||
                checkAuthInfo.PasswordHash != authInfo.PasswordHash ||
                checkAuthInfo.PasswordSalt != authInfo.PasswordSalt)
            {
                if (checkAuthInfo.ID != authInfo.ID)
                {
                    m_Log.Info("ID not equal");
                }
                if (checkAuthInfo.PasswordHash != authInfo.PasswordHash)
                {
                    m_Log.Info("PasswordHash not equal");
                }
                if (checkAuthInfo.PasswordSalt != authInfo.PasswordSalt)
                {
                    m_Log.Info("PasswordSalt not equal");
                }
                return(false);
            }

            m_Log.Info("Testing password check of original data");
            try
            {
                authInfo.CheckPassword("Hello");
            }
            catch
            {
                m_Log.InfoFormat("Hash={0} Salt={1}", authInfo.PasswordHash, authInfo.PasswordSalt);
                return(false);
            }

            m_Log.Info("Testing password check of copy data");
            try
            {
                checkAuthInfo.CheckPassword("Hello");
            }
            catch
            {
                m_Log.InfoFormat("Hash={0} Salt={1}", checkAuthInfo.PasswordHash, checkAuthInfo.PasswordSalt);
                return(false);
            }

            UUID sessionID = UUID.Random;

            m_Log.Info("Testing authenticate with old way");
            try
            {
                m_AuthInfoService.Authenticate(sessionID, m_UserID, "Hello", 30);
            }
            catch
            {
                return(false);
            }
            m_AuthInfoService.ReleaseTokenBySession(m_UserID, sessionID);

            m_Log.Info("Testing authenticate with new way");
            try
            {
                m_AuthInfoService.Authenticate(sessionID, m_UserID, "$1$8b1a9953c4611296a827abf8c47804d7", 30);
            }
            catch (Exception e)
            {
                m_Log.Debug("Exception", e);
                return(false);
            }

            return(true);
        }