public void MinNumberOfLowerCaseCharsTest()
        {
            var p = new PasswordPolicyConfiguration {
                MinNumberOfLowerCaseChars = 3
            };
            var regex = new Regex(PasswordPolicyCheckBuilder.GetRegularExpression(p));

            Assert.IsFalse(regex.IsMatch("123456"));
            Assert.IsFalse(regex.IsMatch("12a3456"));
            Assert.IsFalse(regex.IsMatch("12ab3456"));
            Assert.IsFalse(regex.IsMatch("ABC1234567"));
            Assert.IsTrue(regex.IsMatch("123a4b5c67"));
            Assert.IsTrue(regex.IsMatch("1234567abc"));
            Assert.IsTrue(regex.IsMatch("abc1234567"));
            Assert.IsTrue(regex.IsMatch("óöô1234567"));
        }
        public void MinNumberOfUpperCaseCharsTest()
        {
            var p = new PasswordPolicyConfiguration {
                MinNumberOfUpperCaseChars = 3
            };
            var regex = new Regex(PasswordPolicyCheckBuilder.GetRegularExpression(p));

            Assert.IsFalse(regex.IsMatch("123456"));
            Assert.IsFalse(regex.IsMatch("12A3456"));
            Assert.IsFalse(regex.IsMatch("12AB3456"));
            Assert.IsFalse(regex.IsMatch("abc1234567"));
            Assert.IsTrue(regex.IsMatch("123A4B5C67"));
            Assert.IsTrue(regex.IsMatch("1234567ABC"));
            Assert.IsTrue(regex.IsMatch("ABC1234567"));
            Assert.IsTrue(regex.IsMatch("ÓÖÔ1234567"));
        }
        public ActionResult Index(PasswordModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Example of a check against the UserName. For a simpler implementation we can of course just use
            // `if (model.Password.Contains(model.UserName)) { /* ... */ }`
            string expression =
                PasswordPolicyCheckBuilder.GetRegularExpression(model.UserName, PasswordPolicyCheckRegularExpressionAttribute.PasswordPolicyConfiguration);

            if (!new Regex(expression).IsMatch(model.Password))
            {
                ModelState.AddModelError("Password", "Password must not contain user name.");
                return(View(model));
            }

            return(RedirectToAction("Details", model));
        }