Пример #1
0
        public void Verify_InvalidHash()
        {
            var  buf = IDPasswordCredentials.PlainPasswordToSecureBuffer("@8luE+5ky=");
            var  hash = Manager.ComputeHash(PasswordFamily.Text, buf);
            bool rehash, check;

            hash["salt"] = null;
            try
            {
                check = Manager.Verify(buf, hash, out rehash);
                Aver.Fail("no exception");
            }
            catch (AzosException e)
            {
                Aver.IsTrue(e.Message.Contains("ExtractPasswordHashingOptions((hash|hash[salt])==null)"));
            }

            hash = null;
            try
            {
                check = Manager.Verify(buf, hash, out rehash);
                Aver.Fail("no exception");
            }
            catch (AzosException e)
            {
                Aver.IsTrue(e.Message.Contains("Verify((password|hash)==null)"));
            }
        }
Пример #2
0
        public void CalcStrenghtScore()
        {
            var buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer("qwerty");
            var score = Manager.CalculateStrenghtScore(PasswordFamily.Text, buf);

            Aver.AreEqual(30, score);

            buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer("qwerty123");
            score = Manager.CalculateStrenghtScore(PasswordFamily.Text, buf);
            Aver.AreEqual(93, score);

            buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer("aaaaaaaaaaaaaaaaaaaaaaa");
            score = Manager.CalculateStrenghtScore(PasswordFamily.Text, buf);
            Aver.AreEqual(32, score);

            buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer("@blue+sky=");
            score = Manager.CalculateStrenghtScore(PasswordFamily.Text, buf);
            Aver.AreEqual(198, score);

            buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer("@8luE+5ky=");
            score = Manager.CalculateStrenghtScore(PasswordFamily.Text, buf);
            Aver.AreEqual(299, score);

            buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer(null);
            score = Manager.CalculateStrenghtScore(PasswordFamily.Text, buf);
            Aver.AreEqual(0, score);

            buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer(string.Empty);
            score = Manager.CalculateStrenghtScore(PasswordFamily.Text, buf);
            Aver.AreEqual(0, score);

            buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer("   ");
            score = Manager.CalculateStrenghtScore(PasswordFamily.Text, buf);
            Aver.AreEqual(0, score);
        }
Пример #3
0
        public void AreEquivalent()
        {
            var buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer("@8luE+5ky=");
            var hash1 = Manager.ComputeHash(PasswordFamily.Text, buf);
            var hash2 = HashedPassword.FromString(hash1.ToString());



            Aver.IsTrue(m_Manager.AreEquivalent(hash1, hash2));

            Aver.IsFalse(m_Manager.AreEquivalent(null, null));

            var hash3 = new HashedPassword("OTH", hash2.Family);

            hash3["hash"] = hash2["hash"];
            hash3["salt"] = hash2["salt"];
            Aver.IsFalse(m_Manager.AreEquivalent(hash1, hash3));

            hash2 = Manager.ComputeHash(PasswordFamily.Text, buf);
            Aver.IsFalse(m_Manager.AreEquivalent(hash1, hash2));

            buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer("qwerty");
            hash2 = Manager.ComputeHash(PasswordFamily.Text, buf);
            Aver.IsFalse(m_Manager.AreEquivalent(hash1, hash2));
        }
Пример #4
0
        public void Compute_Verify_Fail()
        {
            var  buf = IDPasswordCredentials.PlainPasswordToSecureBuffer("@8luE+5ky=");
            bool rehash, check;

            var hash = Manager.ComputeHash(PasswordFamily.Text, buf);

            buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer("qwerty");
            check = Manager.Verify(buf, hash, out rehash);
            Aver.IsFalse(check);
        }
Пример #5
0
        public void CalcStrenghtPercent()
        {
            var buf  = IDPasswordCredentials.PlainPasswordToSecureBuffer("qwerty");
            var pcnt = Manager.CalculateStrenghtPercent(PasswordFamily.Text, buf);

            Aver.AreEqual(12, pcnt);

            buf  = IDPasswordCredentials.PlainPasswordToSecureBuffer("@8luE+5ky=");
            pcnt = Manager.CalculateStrenghtPercent(PasswordFamily.Text, buf);
            Aver.AreEqual(100, pcnt);

            buf  = IDPasswordCredentials.PlainPasswordToSecureBuffer("@8luE+5ky=");
            pcnt = Manager.CalculateStrenghtPercent(PasswordFamily.Text, buf, DefaultPasswordManager.TOP_SCORE_MAXIMUM);
            Aver.AreEqual(85, pcnt);
        }
Пример #6
0
        public void CheckServiceActive()
        {
            var pm  = new DefaultPasswordManager(NOPApplication.Instance);
            var buf = IDPasswordCredentials.PlainPasswordToSecureBuffer("@8luE+5ky=");

            try
            {
                var hash = pm.ComputeHash(PasswordFamily.Text, buf);
                Aver.Fail("no exception");
            }
            catch (AzosException e)
            {
                Aver.AreEqual(e.Message, StringConsts.DAEMON_INVALID_STATE +
                              typeof(DefaultPasswordManager).Name);
            }
        }
Пример #7
0
        public void CheckServiceActive()
        {
            var pm  = new DefaultPasswordManager();
            var buf = IDPasswordCredentials.PlainPasswordToSecureBuffer("@8luE+5ky=");

            try
            {
                var hash = pm.ComputeHash(PasswordFamily.Text, buf);
                Assert.Fail("no exception");
            }
            catch (NFXException e)
            {
                Assert.AreEqual(e.Message, StringConsts.SERVICE_INVALID_STATE +
                                typeof(DefaultPasswordManager).Name);
            }
        }
Пример #8
0
        public void Compute_Verify_Pass()
        {
            var  buf = IDPasswordCredentials.PlainPasswordToSecureBuffer("qwerty");
            var  hash = Manager.ComputeHash(PasswordFamily.Text, buf);
            bool rehash, check;

            check = Manager.Verify(buf, hash, out rehash);
            Aver.IsTrue(check);

            buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer("@8luE+5ky=");
            hash  = Manager.ComputeHash(PasswordFamily.Text, buf);
            check = Manager.Verify(buf, hash, out rehash);
            Aver.IsTrue(check);

            check = Manager.Verify(buf, HashedPassword.FromString(hash.ToJSON()), out rehash);
            Aver.IsTrue(check);
        }
Пример #9
0
        public void AreEquivalent()
        {
            var pm = new DefaultPasswordManager(NOPApplication.Instance);

            pm.Start();

            var buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer("@8luE+5ky=");
            var hash1 = Manager.ComputeHash(PasswordFamily.Text, buf);
            var hash2 = HashedPassword.FromString(hash1.ToString());

            try
            {
                Aver.IsTrue(pm.AreEquivalent(hash1, hash2));
                Aver.Fail("no exception");
            }
            catch (AzosException e)
            {
                Aver.AreEqual(e.Message, StringConsts.DAEMON_INVALID_STATE +
                              typeof(DefaultPasswordManager).Name);
            }

            pm.SignalStop();
            pm.WaitForCompleteStop();

            Aver.IsTrue(pm.AreEquivalent(hash1, hash2));

            Aver.IsFalse(pm.AreEquivalent(null, null));

            var hash3 = new HashedPassword("OTH", hash2.Family);

            hash3["hash"] = hash2["hash"];
            hash3["salt"] = hash2["salt"];
            Aver.IsFalse(pm.AreEquivalent(hash1, hash3));

            hash2 = Manager.ComputeHash(PasswordFamily.Text, buf);
            Aver.IsFalse(pm.AreEquivalent(hash1, hash2));

            buf   = IDPasswordCredentials.PlainPasswordToSecureBuffer("qwerty");
            hash2 = Manager.ComputeHash(PasswordFamily.Text, buf);
            Aver.IsFalse(pm.AreEquivalent(hash1, hash2));
        }