Beispiel #1
0
        public void TestHashPassword()
        {
            const string clearTextPassword = "******";
            var helper = new PasswordAssistant();
            var hash = helper.CreateHashFromClearTextPassword(clearTextPassword);

            //Correct password works
            Assert.IsTrue(helper.IsPasswordCorrect("correct horse battery staple", hash));

            //Wrong password doesnt work
            Assert.IsFalse(helper.IsPasswordCorrect("correct horsebattery staple", hash));
            Assert.IsFalse(helper.IsPasswordCorrect("correct horse bättery staple", hash));
            Assert.IsFalse(helper.IsPasswordCorrect("correct horse battery staple ", hash));
            Assert.IsFalse(helper.IsPasswordCorrect("correct horse battery staplE", hash));

            //Wrong salt doesnt work
            var h2 = hash.Clone();
            h2.Salt = PasswordUtils.CreateRandomBytes(new DefaultPasswordConfiguration().SaltByteCount);
            Assert.IsFalse(helper.IsPasswordCorrect("correct horse battery staple", h2));

            //Generated password works
            var genP = helper.CreatePassword();
            var genH = helper.CreateHashFromClearTextPassword(genP);
            Assert.IsTrue(helper.IsPasswordCorrect(genP, genH));
            Assert.AreEqual(new DefaultPasswordConfiguration().PasswordGenerationDefaultLength, genP.Length);
        }
Beispiel #2
0
 public void PasswordGenerationTimeSanityCheck()
 {
     var h = new PasswordAssistant();
     var w = Stopwatch.StartNew();
     Enumerable.Range(1, 10000).Select(_ => h.CreatePassword()).Distinct().Count().Is(10000);
     w.Stop();
     w.ElapsedMilliseconds.Is(e => e < 1000);
 }