Ejemplo n.º 1
0
            private void ApplyNagativeMultipliers(ref int score, RepeatedCharacters repeatedCharacters)
            {
                // negative multipliers
                const int consecutiveUpperCaseMultiplier = 2, consecutiveLowerCaseMultiplier = 2, consecutiveNumberMultiplier = 2;
                const int sequentialLetterMultiplier = 3, sequentialNumberMultiplier = 3, sequentialSymbolMultiplier = 2;

                /* Point deductions for poor practices */
                if ((lowerCase.Count > 0 || upperCase.Count > 0) && new int[] { symbol.Count, number.Count, unicode.Count }.AllZero())
                {
                    // Only Letters
                    score -= password.Length;
                }
                if (new int[] { symbol.Count, lowerCase.Count, unicode.Count, upperCase.Count }.AllZero() && number.Count > 0)
                {
                    // Only Numbers
                    score -= password.Length;
                }
                score -= repeatedCharacters.Deduction;

                score -= upperCase.ConsecutiveCount * consecutiveUpperCaseMultiplier;
                score -= lowerCase.ConsecutiveCount * consecutiveLowerCaseMultiplier;
                score -= number.ConsecutiveCount * consecutiveNumberMultiplier;

                score -= sequentialLetters.SequentialCount * sequentialLetterMultiplier;
                score -= sequentialNumbers.SequentialCount * sequentialNumberMultiplier;
                score -= sequentialSymbols.SequentialCount * sequentialSymbolMultiplier;
                score -= SequentialCharacter.SequentialCharacterCount;
            }
Ejemplo n.º 2
0
            public StringPatternAnalyzerResult Run()
            {
                SpecialCharacter.ResetMiddleSpecialCharacterCount();
                SequentialCharacter.ResetSequentialCharacterCount();
                RepeatedCharacters repeatedCharacters = new RepeatedCharacters
                {
                    Count     = 0,
                    Deduction = 0
                };

                for (int index = 0; index < password.Length; index++)
                {
                    CheckCharacter(index);
                    CheckRepeatedCharacters(index, ref repeatedCharacters);
                }
                sequentialLetters = CheckSequentialLetters();
                sequentialNumbers = CheckSequentialNumbers();
                sequentialSymbols = CheckSequentialSymbols();

                int score = 0;

                ApplyPositiveMultipliers(ref score);
                ApplyNagativeMultipliers(ref score, repeatedCharacters);
                return(StringPatternAnalyzerResult.FromScore(score));
            }
Ejemplo n.º 3
0
            private void CheckRepeatedCharacters(int index, ref RepeatedCharacters repeatedCharacters)
            {
                /* Internal loop through password to check for repeat characters */
                bool repeatedCharactersExist = false;

                for (int i = 0; i < password.Length; i++)
                {
                    if (password[index] == password[i] && index != i)
                    { /* repeat character exists */
                        repeatedCharactersExist = true;

                        /*
                         * Calculate increment deduction based on proximity to identical characters
                         * Deduction is incremented each time a new match is discovered
                         * Deduction amount is based on total password length divided by the
                         * difference of distance between currently selected match
                         */
                        repeatedCharacters.Deduction += Math.Abs(password.Length / (i - index));
                    }
                }
                if (repeatedCharactersExist)
                {
                    repeatedCharacters.Count++;
                    int uniqueCharacterCount = password.Length - repeatedCharacters.Count;
                    repeatedCharacters.Deduction = (uniqueCharacterCount != 0) ? Convert.ToInt32(Math.Ceiling((double)repeatedCharacters.Deduction / uniqueCharacterCount)) : repeatedCharacters.Deduction;
                }
            }
            internal StringPatternAnalyzerResult Run()
            {
                SpecialCharacter.ResetMiddleSpecialCharacterCount();
                SequentialCharacter.ResetSequentialCharacterCount();
                RepeatedCharacters repeatedCharacters = new RepeatedCharacters
                {
                    Count     = 0,
                    Deduction = 0
                };

                for (int index = 0; index < password.Length; index++)
                {
                    CheckCharacter(index);
                    CheckRepeatedCharacters(index, ref repeatedCharacters);
                }
                throw new NotImplementedException();
            }
 private void CheckRepeatedCharacters(int index, ref RepeatedCharacters repeatedCharacters)
 {
     throw new NotImplementedException();
 }