function drush_user_password

8.0.x user.drush.inc drush_user_password($inputs)
6.x user.drush.inc drush_user_password($name)
7.x user.drush.inc drush_user_password($inputs)
4.x user.drush.inc drush_user_password($name)
5.x user.drush.inc drush_user_password($name)
master user.drush.inc drush_user_password($inputs)

Sets the password for the account with the given username

File

commands/user/user.drush.inc, line 394
Drush User Management commands

Code

function drush_user_password($name) {
  if (drush_drupal_major_version() >= 7) {
    $user = user_load_by_name($name);
  }
  else {
    $user = user_load(array('name' => $name));
  }
  if ($user !== FALSE) {
    if (!drush_get_context('DRUSH_SIMULATE')) {
      $pass = drush_get_option('password');
      // If no password has been provided, prompt for one.
      if (empty($pass)) {
        $pass = drush_prompt(dt('Password'), NULL, TRUE, TRUE);
      }
      if (drush_drupal_major_version() >= 8) {
        $user->pass = $pass;
        $user_object = $user->save();
      }
      else {
        $user_object = user_save($user, array('pass' => $pass));
      }
      if ($user_object === FALSE) {
        drush_set_error("Could not change the password for the user account with the name " . $name . "!");
      }
    }
  }
  else {
    drush_set_error("The user account with the name " . $name . " could not be loaded.");
  }
}