title: Custom password ValidationMessageFor
body: <p>Hi I'm trying to create a custom password validation for an authentication system depending on what the password settings are set to using MVC. </p>
  
  <p>In the admin area of the system, the user can choose which settings the password has to adhere to. I want the validation message to reflect that and only show when a password has been entered incorrectly however at present it shows all the time.</p>
  
  <p>This is my view:</p>
  
  <pre><code>@model Domain.Authentication.Users.RegisterDTO
  
  @helper passwordPolicySpecs()
  {
      Services.Settings.Interfaces.ISettingsService _service = Core.Context.Engine.Resolve&lt;Services.Settings.Interfaces.ISettingsService&gt;();
      string passwordWarning = "Password invalid. Password must contain: ";
      passwordWarning = (_service.GetSettingValue&lt;Services.Authentication.Policies.PasswordPolicySettings, bool&gt;(x =&gt; x.PasswordMustBeMinimumLength)) ? passwordWarning + ("At least " + _service.GetSettingValue&lt;Services.Authentication.Policies.PasswordPolicySettings, int&gt;(x =&gt; x.PasswordLength).ToString() + " letters. ") : passwordWarning + "";
      passwordWarning = (_service.GetSettingValue&lt;Services.Authentication.Policies.PasswordPolicySettings, bool&gt;(x =&gt; x.PasswordMustContainANumber)) ? passwordWarning + "A number. " : passwordWarning + "";
      passwordWarning = (_service.GetSettingValue&lt;Services.Authentication.Policies.PasswordPolicySettings, bool&gt;(x =&gt; x.PasswordMustContainASpecialCharacter)) ? passwordWarning + "A special character. " : passwordWarning + "";
      passwordWarning = (_service.GetSettingValue&lt;Services.Authentication.Policies.PasswordPolicySettings, bool&gt;(x =&gt; x.PasswordMustContainLowerCase)) ? passwordWarning + "A lower case letter. " : passwordWarning + "";
      passwordWarning = (_service.GetSettingValue&lt;Services.Authentication.Policies.PasswordPolicySettings, bool&gt;(x =&gt; x.PasswordMustContainUpperCase)) ? passwordWarning + "An upper case letter. " : passwordWarning + "";
      @Html.ValidationMessageFor(model =&gt; model.Password, passwordWarning, new { @class = "text-danger" })
  }
  
  &lt;div class="reset-password-page"&gt;
      &lt;div class="row"&gt;
          &lt;div class="col-xs-12 "&gt;
              &lt;h2&gt;@Core.Helpers.ResourceHelpers.Get("Register")&lt;/h2&gt;
  
              @using (Html.BeginForm("Register", "Authentication", FormMethod.Post, new { id = "RegistrationForm" }))
              {
                  @Html.AntiForgeryToken()
                  @Html.ValidationSummary(true)
  
                  &lt;fieldset&gt;
                      &lt;dl class="dl-horizontal"&gt;
                          &lt;dd&gt;
                              @Html.ValidationMessageFor(model =&gt; model.Email, "", new { @class = "text-danger" })
                              @Html.EditorFor(model =&gt; model.Email, new { htmlAttributes = new { @class = "form-control", placeholder = @Core.Helpers.ResourceHelpers.Get("EmailAddress") } })
                          &lt;/dd&gt;
  
                          &lt;dd&gt;
                              @passwordPolicySpecs()
                              @Html.PasswordFor(model =&gt; model.Password, new { @class = "form-control", placeholder = @Core.Helpers.ResourceHelpers.Get("Password") })
                          &lt;/dd&gt;
  
                          &lt;dd class="padding-top-10"&gt;
                              @Html.ValidationMessageFor(model =&gt; model.PasswordConfirm, "", new { @class = "text-danger" })
                              @Html.PasswordFor(model =&gt; model.PasswordConfirm, new { @class = "form-control", placeholder = @Core.Helpers.ResourceHelpers.Get("ConfirmPassword") })
                          &lt;/dd&gt;
  
                      &lt;/dl&gt;
  
                      &lt;p class="register-btn"&gt;
                          @Html.ValidationMessageFor(model =&gt; model.PhoneNumber, "", new { @class = "text-danger" }) &lt;!--Fill in all fields error--&gt;
                          &lt;input type="submit" value="@Core.Helpers.ResourceHelpers.Get("Register")" class="btn btn-default" /&gt;
                      &lt;/p&gt;
                  &lt;/fieldset&gt;
              }
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>