예제 #1
0
        private void ChangeValue()
        {
            var value = Mathc.ValueOf(this.AssociatedObject.Value, this.AssociatedObject.Maximum, this.mainGrid.ActualWidth);

            ProgressBarProperties.SetValue(this.AssociatedObject, value);
        }
예제 #2
0
        /// <summary>
        /// Checks the password's strength
        /// </summary>
        /// <param name="password">The password to check</param>
        /// <returns>Returns <see cref="PasswordScore"/> rating</returns>
        public static PasswordScore GetPasswordScore(string password)
        {
            // Origin: http://social.msdn.microsoft.com/Forums/vstudio/en-US/5e3f27d2-49af-410a-85a2-3c47e3f77fb1/how-to-check-for-password-strength
            if (string.IsNullOrEmpty(password))
            {
                return(PasswordScore.Blank);
            }

            int score = 1;

            if (password.Length < 4)
            {
                return(PasswordScore.VeryWeak);
            }

            if (password.Length >= 8)
            {
                score++;
            }

            if (password.Length >= 12)
            {
                score++;
            }

            // If 90% of the password are numbers then lower the score
            if (Mathc.ValueOf(Regex.Match(password, @"[0-9]+(\.[0-9][0-9]?)?").Length, password.Length, 100) > 90)
            {
                score--;
            }
            // At least 4 of the chars should be numbers
            else if (Regex.Match(password, @"[0-9]+(\.[0-9][0-9]?)?").Length > 4)
            {
                score++;
            }

            // If 99% of the password are letters then lower the score
            if (Mathc.ValueOf(Regex.Match(password, @"^(?=.*[a-z])(?=.*[A-Z]).+$").Length, password.Length, 100) == 99)
            {
                score--;
            }
            else if (Regex.IsMatch(password, @"^(?=.*[a-z])(?=.*[A-Z]).+$"))
            {
                score++;
            }

            if (Regex.IsMatch(password, @"[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]"))
            {
                score++;
            }

            if (string.Equals(password, "password", StringComparison.CurrentCultureIgnoreCase) ||
                string.Equals(password, "p4ssw0rd", StringComparison.CurrentCultureIgnoreCase) ||
                string.Equals(password, "p455w0rd", StringComparison.CurrentCultureIgnoreCase))
            {
                score = 1;
            }

            if (password.Distinct(new DynamicEqualityComparer <char>((a, b) => a == b)).Count() == 1)
            {
                score = score - 2;
            }

            return((PasswordScore)Mathc.Clamp(score, 1, 5));
        }