コード例 #1
0
        private static void CheckPasswordPolicyCompliance(string password, PasswordComplexitySettings settings)
        {
            if (new Regex(NumbersRegex).Matches(password).Count < settings.MinNumeric)
            {
                throw new PasswordPolicyException("The password must contain " + settings.MinNumeric + " numeric [0-9] characters");
            }

            if (new Regex(NonAlphaNumericRegex).Matches(password).Count < settings.MinNonAlphaNumeric)
            {
                throw new PasswordPolicyException("The password must contain " + settings.MinNonAlphaNumeric + " special characters");
            }

            if (new Regex(UppercaseRegex).Matches(password).Count < settings.MinUpperCase)
            {
                throw new PasswordPolicyException("The password must contain " + settings.MinUpperCase + " uppercase characters");
            }

            if (password.Length < settings.MinLength)
            {
                throw new PasswordPolicyException("The password does not have a length of at least " + settings.MinLength + " characters");
            }

            if (password.Length > settings.MaxLength)
            {
                throw new PasswordPolicyException("The password is longer than " + settings.MaxLength + " characters");
            }
        }
コード例 #2
0
        public static bool TryPasswordPolicyCompliance(string password, PasswordComplexitySettings settings, ref PasswordPolicyException pwdPolicyException)
        {
            try
            {
                CheckPasswordPolicyCompliance(password, settings);
                return(true);
            }
            catch (PasswordPolicyException ex)
            {
                pwdPolicyException = ex;
            }

            return(false);
        }
コード例 #3
0
 public PasswordHasher(PasswordComplexitySettings settings)
 {
     _settings = settings;
 }