From 4308b0b7b2268a1e72f5db4ddf7e22024f646165 Mon Sep 17 00:00:00 2001
From: mqanneh <mqanneh@2833163.no-reply.drupal.org>
Date: Wed, 5 Apr 2017 17:17:58 +0300
Subject: [PATCH] Issue #2867089 by mqanneh: Code logic will never reset
 password expiry

---
 password_policy.module | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/password_policy.module b/password_policy.module
index 7c1bff7..de04a3c 100644
--- a/password_policy.module
+++ b/password_policy.module
@@ -290,14 +290,14 @@ function _password_policy_constraints_validate(&$form, FormStateInterface &$form
 function _password_policy_user_profile_form_submit(array &$form, FormStateInterface $form_state) {
   $current_pass = $form_state->getValue('current_pass');
   $new_pass = $form_state->getValue('pass');
-  $uid = $form_state->getValue('uid');
+  // get the uid from user object.
+  $user = $form_state->getFormObject()->getEntity();
+  $uid = $user->id();
 
   // Update if both current and new password fields are filled out.  Depending
   // on policy settings, user may be allowed to use same password again.
   if ($uid && $current_pass && $new_pass) {
     $date = date('Y-m-d\TH:i:s');
-    /** @var \Drupal\user\Entity\User $user */
-    $user = User::load($uid);
     $user->set('field_last_password_reset', $date);
     $user->set('field_password_expiration', '0');
     $user->save();
-- 
2.7.4

