Пример #1
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));
            }
Пример #2
0
        /// <summary>
        /// All available analyzers will be run against the password.
        /// <para>Internet access will be required.</para>
        /// </summary>
        /// <returns>A <see cref="Task{TResult}"/> with the <see cref="FullAnalyzerResult"/> containing the result of the analysis.</returns>
        public async Task <FullAnalyzerResult> RunFullAnalyzerAsync()
        {
            StringPatternAnalyzer       stringPatternAnalyzer       = new StringPatternAnalyzer(password);
            StringPatternAnalyzerResult stringPatternAnalyzerResult = stringPatternAnalyzer.Run();
            PasswordLeakAnalyzer        passwordLeakAnalyzer        = new PasswordLeakAnalyzer(password);
            PasswordLeakAnalyzerResult  passwordLeakAnalyzerResult  = await passwordLeakAnalyzer.Run();

            return(new FullAnalyzerResult(stringPatternAnalyzerResult, passwordLeakAnalyzerResult));
        }
Пример #3
0
        /// <summary>
        /// Evaluates the strength of the provided password.
        /// </summary>
        /// <param name="password">The password to evaluate.</param>
        /// <returns>A <see cref="Tuple{T1,T2}"/> containing the <see cref="PasswordSecurityLevel"/> and the strength represented by a percentage where higher means stronger against brute-force attacks.</returns>
        public static async Task <(PasswordSecurityLevel, double)> Evaluator(string password)
        {
            PasswordAnalyzer            analyzer = new PasswordAnalyzer(password);
            StringPatternAnalyzerResult result   = await analyzer.RunStringPatternAnalyzerAsync();

            const double minScore = 34d;
            const double maxScore = 215d;
            double       percentage;

            if (result.Score <= minScore)
            {
                percentage = 0d;
            }
            else if (result.Score >= maxScore)
            {
                percentage = 1d;
            }
            else
            {
                percentage = (result.Score - minScore) / (maxScore - minScore);
            }
            return(result.PasswordSecurityLevel, percentage);
        }
Пример #4
0
 /// <summary>
 /// Constructs a new <see cref="FullAnalyzerResult"/> object from existing <seealso cref="AnalyzerResult"/> objects.
 /// </summary>
 /// <param name="stringPatternAnalyzerResult">The <see cref="StringPatternAnalyzerResult"/> for the password.</param>
 /// <param name="passwordLeakAnalyzerResult">The <see cref="PasswordLeakAnalyzerResult"/> for the password.</param>
 public FullAnalyzerResult(StringPatternAnalyzerResult stringPatternAnalyzerResult, PasswordLeakAnalyzerResult passwordLeakAnalyzerResult) : base(stringPatternAnalyzerResult.IsSecure && passwordLeakAnalyzerResult.IsSecure)
 {
     StringPatternAnalyzerResult = stringPatternAnalyzerResult;
     PasswordLeakAnalyzerResult  = passwordLeakAnalyzerResult;
     PasswordSecurityLevel       = (PasswordSecurityLevel)Math.Min((byte)stringPatternAnalyzerResult.PasswordSecurityLevel, (byte)passwordLeakAnalyzerResult.PasswordSecurityLevel);
 }