3

I need a method of changing users passwords which doesn't require email, as such the best solution I can come up with is providing "manager" roles the ability to reset passwords. However we do not want to provide these users with "administer users" permission.

I am thinking the best way of doing this is a view which displays "my team" (uses a user reference on that managers direct reports.) and uses views bulk operations however I can not find anywhere documentation on how to reset users passwords.

Ideally the VBO action would allow managers to select members on their team and reset passwords to a string, then update the user in person.

  • There are no methods for setting user password in Rules, as I can see.You have to write your own action (see Examples module) for this, but this strategy can be dangerous. – kalabro Nov 2 '11 at 12:47
  • Can I do it programmatically? In VBO php? – WestieUK Nov 2 '11 at 13:44
  • You can create an action programmatically. VBO uses actions. – kalabro Nov 2 '11 at 13:52
2

Userplus has an action which changes a users password, I was able to use the below:

/**
 * Implementation of hook_action_info().
 */
function userplus_actions_action_info() {
  $actions = array(
    'userplus_change_password_action' => array(
      'type' => 'user',
      'description' => t('Change user\'s password'),
      'configurable' => TRUE,
      'hooks' => array(),
    ),
  );
  return $actions;
}

/**
 * Action to change a user's password
 */
function userplus_change_password_action_form($context) {
  _user_password_dynamic_validation();
  $form['pass'] = array(
    '#title' => t('New password'),
    '#type' => 'password_confirm',
    '#description' => t('Provide a password for the selected users in both fields.'),
    '#required' => TRUE,
    '#size' => 25,
  );

  return $form;
}

function userplus_change_password_action_submit($form, $form_state) {
  return array('pass' => $form_state['values']['pass']);
}

function userplus_change_password_action(&$user, $context) {
  user_save($user, array('pass' => $context['pass']));
}
2

Another method, for Drupal 7, is to create a rules action, and save it in the file MODULENAME.rules.inc. Change "MODULENAME" by your module name.

/**
 * Implements hook_rules_action_info().
 */
function MODULENAME_rules_action_info() {
 return array(
   'of_client_change_password' => array(
     'label' => t('Change user\'s password'),
     'parameter' => array(
       'account' => array(
         'type' => 'user',
         'label' => t('User'),
        ),
       'password' => array(
         'type' => 'text',
         'label' => t('Password'),
       ),
     ),
     'group' => t('MODULENAME'),
   ),
 );
}

function MODULENAME_change_password($account, $password) {
  // If we pass the password in the $edit array, it will be properly hashed
  $edit['pass'] = $password;
  user_save($account, $edit);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.