コード例 #1
0
        /// <summary>
        /// Attempts to load locally stored copies of the badlists
        /// </summary>
        private bool LoadLocalBadLists()
        {
            try
            {
                // Prepare directory names
                var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                var local10k  = Path.Combine(directory, "BadLists\\top-10k-passwords.txt");
                var local100k = Path.Combine(directory, "BadLists\\top-100k-passwords.txt");

                // Load local copy
                if (File.Exists(local10k))
                {
                    Top10kBadList = new TestBadList(local10k);
                }

                if (File.Exists(local100k))
                {
                    Top100kBadList = new TestBadList(local100k);
                }

                if (Top10kBadList != null && Top100kBadList != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
コード例 #2
0
        /// <summary>
        /// Runs each applicable bad list test against the provided password
        /// </summary>
        /// <param name="password">The password to test</param>
        /// <param name="isL33t">Specifies whether this password is a l33t variant</param>
        /// <param name="userBadList">An optional bad list to check against containing user information</param>
        private void RunBadListTests(string password, bool isL33t, TestBadList userBadList = null)
        {
            var reversed = Reverse(password);

            if (BadListsLoaded)
            {
                // Test top 10K list
                if (isL33t)
                {
                    RunTest(password, Top10kBadList);
                    RunTest(reversed, Top10kBadList);
                }

                // Test top 100K list
                if (isL33t == false)
                {
                    RunTest(password, Top100kBadList);
                    RunTest(reversed, Top100kBadList);
                }
            }

            // Test user list
            if (userBadList != null)
            {
                RunTest(password, userBadList);
                RunTest(reversed, userBadList);
            }
        }
コード例 #3
0
        /// <summary>
        /// Runs scoring and validation on the specified password
        /// </summary>
        /// <param name="password">The password to test</param>
        /// <param name="userInformation">An optional list containing user information to compare against the password</param>
        /// <exception cref="ArgumentNullException"></exception>
        public bool TestAndScore(string password, IEnumerable <string> userInformation = null)
        {
            // Input validation
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException(nameof(password), "Must provide password to analyse");
            }

            // Reset
            FailureMessages.Clear();
            Score = 0;

            // Get l33t variants
            IEnumerable <string> l33t;

            if (CustomReplacements == null)
            {
                l33t = L33tDecoderService.Decode(password, L33tLevel.Advanced);
            }
            else
            {
                l33t = L33tDecoderService.Decode(password, L33tLevel.Custom, CustomReplacements);
            }

            // Run general tests
            RunPasswordTests(password);

            // Run list tests
            TestBadList userBadList = null;

            if (userInformation != null)
            {
                userBadList = new TestBadList(userInformation);
            }

            RunBadListTests(password, false, userBadList);

            foreach (var variant in l33t)
            {
                if (Settings.ExitOnFailure == false || FailureMessages.Count == 0)
                {
                    RunBadListTests(variant, true, userBadList);
                }
            }

            // Remove duplicate failure messages (l33t variants may cause this)
            FailureMessages = FailureMessages.Distinct().ToList();

            // Return result
            if (Settings.MinScore > 0)
            {
                return(Score >= Settings.MinScore && FailureMessages.Count == 0);
            }
            else
            {
                return(FailureMessages.Count == 0);
            }
        }
コード例 #4
0
        /// <summary>
        /// Attempts to load remote copies of the badlists
        /// </summary>
        private bool LoadRemoteBadLists()
        {
            // Prepare directory names
            var appdata10k  = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Easy-Password-Validator\\BadLists\\top-10k-passwords.txt");
            var appdata100k = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Easy-Password-Validator\\BadLists\\top-100k-passwords.txt");

            var remote10k  = "https://raw.githubusercontent.com/thirstyape/Easy-Password-Validator/master/BadLists/top-10k-passwords.txt";
            var remote100k = "https://raw.githubusercontent.com/thirstyape/Easy-Password-Validator/master/BadLists/top-100k-passwords.txt";

            // Load remote copy
            try
            {
                using var client = new WebClient();

                if (Top10kBadList == null)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(appdata10k));
                    client.DownloadFile(remote10k, appdata10k);
                    Top10kBadList = new TestBadList(appdata10k);
                }

                if (Top100kBadList == null)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(appdata100k));
                    client.DownloadFile(remote100k, appdata100k);
                    Top100kBadList = new TestBadList(appdata100k);
                }

                if (Top10kBadList != null && Top100kBadList != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
コード例 #5
0
        /// <summary>
        /// Loads the badlists into memory
        /// </summary>
        private void LoadBadLists()
        {
            // Prepare directory names
            var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var local10k  = Path.Combine(directory, "BadLists\\top-10k-passwords.txt");
            var local100k = Path.Combine(directory, "BadLists\\top-100k-passwords.txt");

            var appdata10k  = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Easy-Password-Validator\\BadLists\\top-10k-passwords.txt");
            var appdata100k = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Easy-Password-Validator\\BadLists\\top-100k-passwords.txt");

            var remote10k  = "https://raw.githubusercontent.com/thirstyape/Easy-Password-Validator/master/BadLists/top-10k-passwords.txt";
            var remote100k = "https://raw.githubusercontent.com/thirstyape/Easy-Password-Validator/master/BadLists/top-100k-passwords.txt";

            // Load local copy
            if (File.Exists(local10k))
            {
                Top10kBadList = new TestBadList(local10k);
            }

            if (File.Exists(local100k))
            {
                Top100kBadList = new TestBadList(Path.Combine(directory, "BadLists\\top-100k-passwords.txt"));
            }

            if (Top10kBadList != null || Top100kBadList != null)
            {
                return;
            }

            // Load remote copy
            Directory.CreateDirectory(Path.GetDirectoryName(appdata10k));
            Directory.CreateDirectory(Path.GetDirectoryName(appdata100k));

            using var client = new WebClient();

            client.DownloadFile(remote10k, appdata10k);
            client.DownloadFile(remote100k, appdata100k);

            Top10kBadList  = new TestBadList(appdata10k);
            Top100kBadList = new TestBadList(appdata100k);
        }