public void SuggestionsTest()
        {
            var zx = new PasswordMetric(new DefaultMatcherFactory());

            for (int i = 0; i < testPasswords.Length; ++i)
            {
                var password = testPasswords[i];

                var result = zx.EvaluatePassword(password);
                O("");
                O("Password:         {0}", result.Password);
                for (int j = 0; j < result.suggestions.Count(); ++j)
                {
                    var realSuggestion     = Utility.GetSuggestion(result.suggestions[j]);
                    var expectedSuggestion = testSuggestions[i, j];
                    O("Suggestion:          {0}", realSuggestion);
                    O("Expected Suggestion: {0}", expectedSuggestion);


                    Assert.AreEqual(realSuggestion, expectedSuggestion);
                }

                O("");
                O("=========================================");
            }
        }
Exemplo n.º 2
0
        public void MatchesSwissGermanKeyboardPattern()
        {
            var swissKeyboardPatterns = new List <string> {
                "löäü'", "ö-.,m"
            };

            var passwordChecker = new PasswordMetric();

            foreach (var pattern in swissKeyboardPatterns)
            {
                var metric = passwordChecker.EvaluatePassword(pattern);

                foreach (var match in metric.MatchSequence)
                {
                    var spatialMatch = match as SpatialMatch;

                    Assert.AreNotEqual(null, spatialMatch);
                    Assert.AreEqual("Swiss German", spatialMatch.Graph);
                    Assert.AreEqual(0, spatialMatch.ShiftedCount);
                    Assert.AreEqual(2, spatialMatch.Turns);

                    Assert.AreEqual(0, match.Cardinality);
                    Assert.AreEqual(0, match.Begin);
                    Assert.AreEqual(pattern.Length - 1, match.End);
                    Assert.AreEqual(pattern, match.Token);
                }
            }
        }
Exemplo n.º 3
0
        public void MatchesFrenchKeyboardPattern()
        {
            var frenchKeyboardPatterns = new List <string> {
                "*ùmlkj", "bn,;:!"
            };

            var passwordChecker = new PasswordMetric();

            foreach (var pattern in frenchKeyboardPatterns)
            {
                var metric = passwordChecker.EvaluatePassword(pattern);

                foreach (var match in metric.MatchSequence)
                {
                    var spatialMatch = match as SpatialMatch;

                    Assert.AreNotEqual(null, spatialMatch);
                    Assert.AreEqual("French", spatialMatch.Graph);
                    Assert.AreEqual(0, spatialMatch.ShiftedCount);
                    Assert.AreEqual(1, spatialMatch.Turns);

                    Assert.AreEqual(0, match.Cardinality);
                    Assert.AreEqual(0, match.Begin);
                    Assert.AreEqual(pattern.Length - 1, match.End);
                    Assert.AreEqual(pattern, match.Token);
                }
            }
        }
Exemplo n.º 4
0
        public void EvaluatesEmptyPasswordWithAnEntropyOfZero()
        {
            var passwordChecker = new PasswordMetric();

            var result = passwordChecker.EvaluatePassword("");

            Assert.AreEqual(0.0, result.Entropy);
        }
 public void SinglePasswordTest2()
 {
     //var res = Zxcvbn.Zxcvbn.MatchPassword("p@sswordpassword");
     //var res = Zxcvbn.Zxcvbn.MatchPassword("Password");
     // var res = Zxcvbn.Zxcvbn.MatchPassword("qwER43@!");
     //var res = Zxcvbn.Zxcvbn.MatchPassword("temppass22");
     var res = PasswordMetric.MatchPassword("abcabc");
 }
Exemplo n.º 6
0
        public void EvaluatesPasswordEntropy()
        {
            var passwordChecker = new PasswordMetric();

            var a    = passwordChecker.EvaluatePassword("a");
            var aaaa = passwordChecker.EvaluatePassword("aaaa");
            var abab = passwordChecker.EvaluatePassword("abab");
            var ABab = passwordChecker.EvaluatePassword("ABab");

            Assert.IsTrue(aaaa.Entropy > a.Entropy);
            Assert.IsTrue(abab.Entropy > aaaa.Entropy);
            Assert.IsTrue(ABab.Entropy > abab.Entropy);
        }
Exemplo n.º 7
0
        public void LoadsMesserliDictionary()
        {
            var passwordChecker = new PasswordMetric();
            var password        = "******";
            var metric          = passwordChecker.EvaluatePassword(password);

            foreach (var match in metric.MatchSequence)
            {
                Assert.AreEqual(10, match.Cardinality);
                Assert.AreEqual(password, match.Token);
                Assert.AreEqual(0, match.Begin);
                Assert.AreEqual(password.Length - 1, match.End);

                var dictionaryMatch = match as DictionaryMatch;

                Assert.AreNotEqual(null, dictionaryMatch);
                Assert.AreEqual("messerli", dictionaryMatch.DictionaryName);
                Assert.AreEqual(1, dictionaryMatch.UppercaseEntropy);
            }
        }
        public void WarningTest()
        {
            var zx = new PasswordMetric(new DefaultMatcherFactory());

            for (int i = 0; i < testPasswords.Length; ++i)
            {
                var password        = testPasswords[i];
                var expectedWarning = testWarnings[i];

                var result      = zx.EvaluatePassword(password);
                var realWarning = Utility.GetWarning(result.warning);
                O("");
                O("Password:         {0}", result.Password);
                O("Warning:          {0}", realWarning);
                O("Expected Warning: {0}", expectedWarning);


                O("");
                O("=========================================");

                Assert.AreEqual(realWarning, expectedWarning);
            }
        }
        public void RunAllTestPasswords()
        {
            var zx = new PasswordMetric(new DefaultMatcherFactory());

            for (int i = 0; i < testPasswords.Length; ++i)
            {
                var password = testPasswords[i];

                var result = zx.EvaluatePassword(password);

                O("");
                O("Password:        {0}", result.Password);
                O("Entropy:         {0}", result.Entropy);
                O("Crack Time (s):  {0}", result.CrackTime);
                O("Crack Time (d):  {0}", result.CrackTimeDisplay);
                O("Score (0 to 4):  {0}", result.Score);
                O("Calc time (ms):  {0}", result.CalcTime);
                O("--------------------");

                foreach (var match in result.MatchSequence)
                {
                    if (match != result.MatchSequence.First())
                    {
                        O("+++++++++++++++++");
                    }

                    O(match.Token);
                    O("Pattern:      {0}", match.Pattern);
                    O("Entropy:      {0}", match.Entropy);

                    if (match is DictionaryMatch)
                    {
                        var dm = match as DictionaryMatch;
                        O("Dict. Name:   {0}", dm.DictionaryName);
                        O("Rank:         {0}", dm.Rank);
                        O("Base Entropy: {0}", dm.BaseEntropy);
                        O("Upper Entpy:  {0}", dm.UppercaseEntropy);
                    }

                    if (match is L33tDictionaryMatch)
                    {
                        var lm = match as L33tDictionaryMatch;
                        O("L33t Entpy:   {0}", lm.L33tEntropy);
                        O("Unleet:       {0}", lm.MatchedWord);
                    }

                    if (match is SpatialMatch)
                    {
                        var sm = match as SpatialMatch;
                        O("Graph:        {0}", sm.Graph);
                        O("Turns:        {0}", sm.Turns);
                        O("Shifted Keys: {0}", sm.ShiftedCount);
                    }

                    if (match is RepeatMatch)
                    {
                        var rm = match as RepeatMatch;
                        O("Repeat char:  {0}", rm.RepeatChar);
                    }

                    if (match is SequenceMatch)
                    {
                        var sm = match as SequenceMatch;
                        O("Seq. name:    {0}", sm.SequenceName);
                        O("Seq. size:    {0}", sm.SequenceSize);
                        O("Ascending:    {0}", sm.Ascending);
                    }

                    if (match is DateMatch)
                    {
                        var dm = match as DateMatch;
                        O("Day:          {0}", dm.Day);
                        O("Month:        {0}", dm.Month);
                        O("Year:         {0}", dm.Year);
                        O("Separator:    {0}", dm.Separator);
                    }
                }

                O("");
                O("=========================================");

                Assert.AreEqual(expectedEntropies[i], result.Entropy);
            }
        }
Exemplo n.º 10
0
 public void SinglePasswordTest()
 {
     var res = PasswordMetric.MatchPassword("||ke");
 }
Exemplo n.º 11
0
        public void EmptyPassword()
        {
            var res = PasswordMetric.MatchPassword("");

            Assert.AreEqual(0, res.Entropy);
        }