質問

I need to record when a user changes his password in drupal 7. When a registered user changes their password the platform should store a record in a database.

I appreciate any guidance.

thanks :)

役に立ちましたか?

解決 2

I needed to do something similar the other day and came up with this solution using hook_user_presave()

function MYMODULE_user_presave(&$edit, $account, $category) {
  if (!empty($edit['pass']) && $account->pass != $edit['pass']) {
    watchdog('MYMODULE', t('Password changed for %name', array('%name' => $account->name)));
  }
}

他のヒント

Create a hook_form_user_profile_form_alter() and add an extra #submit handler (to the form) in which you do something like this:

if (!empty($form_state['values']['pass']) && $form_state['values']['pass'] != $form_state['values']['current_pass']) {
  watchdog('user', 'The %name changed his password.', array('%name' => $account->name), WATCHDOG_NOTICE);
}

I have a sandbox module to do this: https://drupal.org/sandbox/dhalbert/1695174 ("Password Change Log").

It uses a hook_user_update() but is otherwise quite similar to the accepted answer.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top