Answers.Body: <p>I wasn't validating againts the field newPassword, only validating against password. Hence why I wasn't getting any feedback. Duplicating the validation for newPassword seems to have resolved this.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-04T14:29:42.020Z
Answers.LastActivityDate: 2016-10-04T18:04:10.827Z
Answers.LastEditDate: 2016-10-04T18:04:10.827Z
Answers.UserDisplayName: Terry Upton
Body: <p>I have the following code to further validate passwords when creating/registering an account which is working fine.</p>
  
  <p>However, when trying to use this same validation for resetting a password I am not getting any errors back?</p>
  
  <p>Can anyone point me in the right direction...?</p>
  
  <pre><code>public function onBeforeSetPassword(Event $event)
  {
      $user = $event-&gt;params['user'];
      $password = $event-&gt;params['password'];
  
      if (mb_strlen($password) &lt; 8)
      {
          $user-&gt;addError('password', 'Sorry but your password must be at least 8 characters.');
          $event-&gt;performAction = false;
      }
  
      if (!preg_match('/(\d.*[A-Z]|[A-Z].*\d)/', $password))
      {
          $user-&gt;addError('password', 'Sorry but your password must contain at least one uppercase letter and one number.');
          $event-&gt;performAction = false;
      }
  }
  </code></pre>
  
  <p>On the template:</p>
  
  <pre><code>{% if account is defined and account.getErrors('password') %}
      {% include '_includes/formError' with { error : account.getErrors('password')|join('&lt;br&gt;') } %}
  {% endif %}
  </code></pre>
  
  <p>Thanks.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-02T17:02:26.293Z
Comments.Text: Is this in the context of a front-end registered user or a CP registered one? Also, if you `Craft::log()` in there, is your method even being hit in the reset password scenario?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-02T17:02:37.883Z
Comments.Text: FWIW, I checked and the `onBeforeSetPassword` event does seem to fire when passwords are reset. You can confirm this yourself by adding `MyPluginHandlePlugin::log("Setting password...");` to your event handler (obviously, replace `MyPluginHandle` with the real handle for your plugin), and then open up your plugin's log file at `/craft/storage/runtime/logs/mypluginhandle.log`, after resetting a password. If the event does indeed fire, there's something else amiss with your code somewhere.
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-04T06:59:59.673Z
Comments.Text: @BradBell this is on a front end user (actually customers for commerce) form. I will try what Mats has suggest to see if firing.
Comments.UserDisplayName: Terry Upton
Tags: <users><registration><validation><password>
Title: Password validation for resetting password
ThreadText: # Password validation for resetting password
  
  (Asked by: username_0 on 2016-10-02)
  
  I have the following code to further validate passwords when creating/registering an account which is working fine.
  
  However, when trying to use this same validation for resetting a password I am not getting any errors back?
  
  Can anyone point me in the right direction...?
  
  ```
  public function onBeforeSetPassword(Event $event)
  {
      $user = $event->params['user'];
      $password = $event->params['password'];
  
      if (mb_strlen($password) < 8)
      {
          $user->addError('password', 'Sorry but your password must be at least 8 characters.');
          $event->performAction = false;
      }
  
      if (!preg_match('/(\d.*[A-Z]|[A-Z].*\d)/', $password))
      {
          $user->addError('password', 'Sorry but your password must contain at least one uppercase letter and one number.');
          $event->performAction = false;
      }
  }
  
  ```
  
  On the template:
  
  ```
  {% if account is defined and account.getErrors('password') %}
      {% include '_includes/formError' with { error : account.getErrors('password')|join('<br>') } %}
  {% endif %}
  
  ```
  
  Thanks.
  
  **Tags:** users, registration, validation, password
  
  > **Comments:**
  > **username_1**: Is this in the context of a front-end registered user or a CP registered one? Also, if you `Craft::log()` in there, is your method even being hit in the reset password scenario?  
  > **username_2**: FWIW, I checked and the `onBeforeSetPassword` event does seem to fire when passwords are reset. You can confirm this yourself by adding `MyPluginHandlePlugin::log("Setting password...");` to your event handler (obviously, replace `MyPluginHandle` with the real handle for your plugin), and then open up your plugin's log file at `/craft/storage/runtime/logs/mypluginhandle.log`, after resetting a password. If the event does indeed fire, there's something else amiss with your code somewhere.  
  > **username_0**: @username_1 this is on a front end user (actually customers for commerce) form. I will try what username_2 has suggest to see if firing.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-10-04. Score: 2 | Accepted answer
  
  I wasn't validating againts the field newPassword, only validating against password. Hence why I wasn't getting any feedback. Duplicating the validation for newPassword seems to have resolved this.
  
  
  ---
  
  