public IEnumerable <ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            PasswordPolicy policy = Chimera.Authentication.Shared.Configuration.Settings.GetPasswordPolicy();

            var rule = new ModelClientValidationRule();

            rule.ValidationType = "passwordpolicy";
            rule.ValidationParameters["policyexpr"] = policy.GetExpression();
            rule.ErrorMessage = policy.GetDescription(metadata.DisplayName);
            yield return(rule);
        }
Esempio n. 2
0
        private void SetPassword(string newPassword, PasswordPolicy passwordPolicy)
        {
            if (newPassword != null)
            {
                if (!passwordPolicy.IsValid(newPassword))
                {
                    throw new InvalidPasswordException(passwordPolicy.GetDescription(_.Auth.Password));
                }

                string algorithm = Configuration.Settings.PasswordHashAlgorithm;
                byte[] salt, hash;
                GeneratePasswordHash(newPassword, algorithm, out salt, out hash);

                Publish(new PasswordChangedEvent(Id, salt, hash, algorithm));
            }
            else
            {
                Publish(new PasswordChangedEvent(Id, null, null, null));
            }
        }
Esempio n. 3
0
        public void CanDescribeValidationRules()
        {
            // Arrange
            PasswordPolicy policy1 = new PasswordPolicy {
                MinPasswordLength = 5
            };
            PasswordPolicy policy2 = new PasswordPolicy {
                MinNoOfLowerCaseChars = 2
            };
            PasswordPolicy policy3 = new PasswordPolicy {
                MinNoOfUpperCaseChars = 2
            };
            PasswordPolicy policy4 = new PasswordPolicy {
                MinNoOfNumbers = 2
            };
            PasswordPolicy policy5 = new PasswordPolicy {
                MaxNoOfAllowedCharacterRepetitions = 3
            };
            PasswordPolicy policy6 = new PasswordPolicy
            {
                MinPasswordLength     = 1,
                MinNoOfLowerCaseChars = 2,
                MinNoOfUpperCaseChars = 3,
                MinNoOfNumbers        = 4,
                MaxNoOfAllowedCharacterRepetitions = 5
            };
            PasswordPolicy policy7 = new PasswordPolicy();

            // Act + Assert
            Assert.AreEqual("password must be at least 5 characters long", policy1.GetDescription("password"));
            Assert.AreEqual("password must contain at least 2 lower case characters", policy2.GetDescription("password"));
            Assert.AreEqual("password must contain at least 2 upper case characters", policy3.GetDescription("password"));
            Assert.AreEqual("password must contain at least 2 numbers", policy4.GetDescription("password"));
            Assert.AreEqual("password must contain at most 3 character repetitions", policy5.GetDescription("password"));
            Assert.AreEqual("password must be at least 1 characters long, contain at least 2 lower case characters, contain at least 3 upper case characters, contain at least 4 numbers, contain at most 5 character repetitions", policy6.GetDescription("password"));
            Assert.IsNull(policy7.GetDescription("password"));
        }
    public void CanDescribeValidationRules()
    {
      // Arrange
      PasswordPolicy policy1 = new PasswordPolicy { MinPasswordLength = 5 };
      PasswordPolicy policy2 = new PasswordPolicy { MinNoOfLowerCaseChars = 2 };
      PasswordPolicy policy3 = new PasswordPolicy { MinNoOfUpperCaseChars = 2 };
      PasswordPolicy policy4 = new PasswordPolicy { MinNoOfNumbers = 2 };
      PasswordPolicy policy5 = new PasswordPolicy { MaxNoOfAllowedCharacterRepetitions = 3 };
      PasswordPolicy policy6 = new PasswordPolicy 
      {
        MinPasswordLength = 1,
        MinNoOfLowerCaseChars = 2,
        MinNoOfUpperCaseChars = 3,
        MinNoOfNumbers = 4,
        MaxNoOfAllowedCharacterRepetitions = 5
      };
      PasswordPolicy policy7 = new PasswordPolicy();

      // Act + Assert
      Assert.AreEqual("password must be at least 5 characters long", policy1.GetDescription("password"));
      Assert.AreEqual("password must contain at least 2 lower case characters", policy2.GetDescription("password"));
      Assert.AreEqual("password must contain at least 2 upper case characters", policy3.GetDescription("password"));
      Assert.AreEqual("password must contain at least 2 numbers", policy4.GetDescription("password"));
      Assert.AreEqual("password must contain at most 3 character repetitions", policy5.GetDescription("password"));
      Assert.AreEqual("password must be at least 1 characters long, contain at least 2 lower case characters, contain at least 3 upper case characters, contain at least 4 numbers, contain at most 5 character repetitions", policy6.GetDescription("password"));
      Assert.IsNull(policy7.GetDescription("password"));
    }