예제 #1
0
        /// <summary>
        /// Find dictionary matches in <paramref name="password"/>.
        /// </summary>
        /// <param name="password">The password to check.</param>
        /// <returns>An enumerable of dictionary matches.</returns>
        public virtual IEnumerable <Match> MatchPassword(string password)
        {
            var passwordLower = password.ToLower();
            var length        = passwordLower.Length;
            var matches       = new List <Match>();

            for (var i = 0; i < length; i++)
            {
                for (var j = i; j < length; j++)
                {
                    var passwordSub = passwordLower.Substring(i, j - i + 1);
                    if (rankedDictionary.ContainsKey(passwordSub))
                    {
                        var match = new DictionaryMatch
                        {
                            i              = i,
                            j              = j,
                            Token          = password.Substring(i, j - i + 1),
                            MatchedWord    = passwordSub,
                            Rank           = rankedDictionary[passwordSub],
                            DictionaryName = dictionaryName,
                            Reversed       = false,
                            L33t           = false,
                        };

                        matches.Add(match);
                    }
                }
            }

            return(matches.OrderBy(m => m.i).ThenBy(m => m.j));
        }
예제 #2
0
        private void CalculateEntropyForMatch(DictionaryMatch match)
        {
            match.BaseEntropy      = Math.Log(match.Rank, 2);
            match.UppercaseEntropy = PasswordScoring.CalculateUppercaseEntropy(match.Token);

            match.Entropy = match.BaseEntropy + match.UppercaseEntropy;
        }
예제 #3
0
        /// <summary>
        /// Create a new l33t match from a dictionary match
        /// </summary>
        /// <param name="dm">The dictionary match to initialise the l33t match from</param>
        public L33tDictionaryMatch(DictionaryMatch dm)
        {
            this.BaseEntropy      = dm.BaseEntropy;
            this.Cardinality      = dm.Cardinality;
            this.DictionaryName   = dm.DictionaryName;
            this.Entropy          = dm.Entropy;
            this.Begin            = dm.Begin;
            this.End              = dm.End;
            this.MatchedWord      = dm.MatchedWord;
            this.Pattern          = dm.Pattern;
            this.Rank             = dm.Rank;
            this.Token            = dm.Token;
            this.UppercaseEntropy = dm.UppercaseEntropy;

            Subs = new Dictionary <char, char>();
        }
예제 #4
0
        /// <summary>
        /// Create a new l33t match from a dictionary match
        /// </summary>
        /// <param name="dm">The dictionary match to initialise the l33t match from</param>
        public L33tDictionaryMatch(DictionaryMatch dm)
        {
            this.BaseEntropy = dm.BaseEntropy;
            this.Cardinality = dm.Cardinality;
            this.DictionaryName = dm.DictionaryName;
            this.Entropy = dm.Entropy;
            this.i = dm.i;
            this.j = dm.j;
            this.MatchedWord = dm.MatchedWord;
            this.Pattern = dm.Pattern;
            this.Rank = dm.Rank;
            this.Token = dm.Token;
            this.UppercaseEntropy = dm.UppercaseEntropy;

            Subs = new Dictionary<char, char>();
        }
예제 #5
0
        /// <summary>
        /// Create a new l33t match from a dictionary match
        /// </summary>
        /// <param name="dm">The dictionary match to initialise the l33t match from</param>
        public L33tDictionaryMatch(DictionaryMatch dm)
        {
            BaseEntropy    = dm.BaseEntropy;
            Cardinality    = dm.Cardinality;
            DictionaryName = dm.DictionaryName;
            Entropy        = dm.Entropy;
            i                = dm.i;
            j                = dm.j;
            MatchedWord      = dm.MatchedWord;
            Pattern          = dm.Pattern;
            Rank             = dm.Rank;
            Token            = dm.Token;
            UppercaseEntropy = dm.UppercaseEntropy;

            Subs = new Dictionary <char, char>();
        }
예제 #6
0
        private void CalculateEntropyForMatch(DictionaryMatch match)
        {
            match.BaseEntropy = Math.Log(match.Rank, 2);
            match.UppercaseEntropy = PasswordScoring.CalculateUppercaseEntropy(match.Token);

            match.Entropy = match.BaseEntropy + match.UppercaseEntropy;
        }