Hello! This module is excellent - thank you for all your work!

I've implemented password policy and it seems that it doesn't update the password_policy_history table with the user's latest password hash & creation time when they UPDATE their password.... only when the create their password the first time.

Is this the intended functionality? Had anyone else experienced this?

I had to make the following changes to get this to update as expected when a user changes/updates their password. Or am i missing something/doing something wrong? Any help would be greatly appreciated!

in password_policy_password_tab.pages.inc
in function password_policy_password_tab_submit($form, &$form_state)
changed:

  user_save($account, array('pass' => $form_state['values']['pass']));

to:

  user_save($account, array('pass' => $form_state['values']['pass']));

		if(!empty($form_state['values']['_account']->pass)){ 
           _password_policy_store_hash($account->uid, $form_state['values']['_account']->pass); 
		} 


in password_policy.module
in function password_policy_user($op, &$edit, &$account, $category = NULL)
changed:

    case 'update':
      if ($account->force_password_change && isset($account->pass) && $user->uid == $account->uid) {
        db_query('UPDATE {password_policy_force_change} SET force_change = 0 WHERE uid = %d', $account->uid);
      }
      elseif (!empty($edit['force_password_change'])) {
        db_query('UPDATE {password_policy_force_change} SET force_change = 1 WHERE uid = %d', $account->uid);
        if ($user->uid != $account->uid) {
          drupal_set_message(t('@user will be required to change their password the next time they log in.', array('@user' => $account->name)));
        }
        watchdog('password policy', '@user flagged to change password on next login by @admin', array('@user' => $account->name, '@admin' => $user->name), WATCHDOG_NOTICE);
      }

      if (isset($edit['status']) && $edit['status'] != $account->status && $edit['status'] == 1) {
        // Account is being unblocked.
        db_query('UPDATE {password_policy_expiration} SET unblocked = %d WHERE uid = %d', time(), $account->uid);
      }
	  
      break;

to:


    case 'update':
      if ($account->force_password_change && isset($account->pass) && $user->uid == $account->uid) {
        db_query('UPDATE {password_policy_force_change} SET force_change = 0 WHERE uid = %d', $account->uid);
      }
      elseif (!empty($edit['force_password_change'])) {
        db_query('UPDATE {password_policy_force_change} SET force_change = 1 WHERE uid = %d', $account->uid);
        if ($user->uid != $account->uid) {
          drupal_set_message(t('@user will be required to change their password the next time they log in.', array('@user' => $account->name)));
        }
        watchdog('password policy', '@user flagged to change password on next login by @admin', array('@user' => $account->name, '@admin' => $user->name), WATCHDOG_NOTICE);
      }

      if (isset($edit['status']) && $edit['status'] != $account->status && $edit['status'] == 1) {
        // Account is being unblocked.
        db_query('UPDATE {password_policy_expiration} SET unblocked = %d WHERE uid = %d', time(), $account->uid);
      }

		if(!empty($edit['mail'])){
          _password_policy_store_hash($account->uid, $account->pass);
		} 
	  
      break;



Without the above, the users password expiration essentially wouldn't update if they updated their password and they'd still get (incorrect) notices.

PS - Recently i patched password policy module for phpass module integration http://drupal.org/node/598424 ... not sure if that affected this. But the above fixes i mention won't work verbatim for you if you don't have that patch.

Comments

erikwebb’s picture

Status: Active » Needs work

I'll take a look at this over the next few days.

erikwebb’s picture

Status: Needs work » Needs review
StatusFileSize
new1.12 KB

I've actually decided to solve this in a little different way. I'm taking away the logic from any individual form and instead doing it when a user object is updated. Please test.

Status: Needs review » Needs work

The last submitted patch, password_policy-new_password_history-1653242-2.patch, failed testing.

erikwebb’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, password_policy-new_password_history-1653242-2.patch, failed testing.

SchwebDesign’s picture

Thanks a lot erikwebb. I'll test this out this week.

erikwebb’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, password_policy-new_password_history-1653242-2.patch, failed testing.

erikwebb’s picture

I don't understand how this patch could be affecting the uppercase constraint.

@SchwebDesign - Were you able to test this?

SchwebDesign’s picture

Erikwebb, again thank for your help. Unfortunately, no i haven't been able to test this. I'll definitely get to this asap, but at this point i'm not able to spend much extra time on the site i previously mentioned, and the solution i implemented temporarily seems to be sufficient. Although i do think yours is better after looking at the patch itself. I'll definitely comment back here when i am able to test this!

erikwebb’s picture

Status: Needs work » Needs review
erikwebb’s picture

Status: Needs review » Needs work

The last submitted patch, password_policy-new_password_history-1653242-2.patch, failed testing.

erikwebb’s picture

Title: user update/change password doesn't update password_policy_expiration with pass and creation time » Password update doesn't store new password history
Version: 6.x-1.4 » 6.x-1.5
Status: Needs work » Needs review
StatusFileSize
new1.28 KB
deekayen’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.