Problem/Motivation

In uuid.core.inc:

  if (isset($entity->pass)
    && (!('$S$D' == substr($entity->pass, 0, 4)) || preg_match('/^[a-f0-9]{32}$/', $entity->pass))) {
    // Ensure user's password is hashed.
    $entity->pass = user_hash_password($entity->pass);
  }

we assume that user_hash_password() is defined, which can be not the case

Proposed resolution

Include password.inc if user_hash_password() is not defined.

Remaining tasks

Write the patch

User interface changes

No UI change

API changes

No API change

Data model changes

No data model change

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

valthebald created an issue. See original summary.

valthebald’s picture

skwashd’s picture

Status: Needs review » Postponed (maintainer needs more info)

@valthebald what are the circumstances where password.inc isn't already included?

valthebald’s picture

@skwashd well, password.inc is not included during the bootstrap...
My scenario was user entities (node authors) as dependencies of deployed nodes (deploy module pushes to services module on another server)

valthebald’s picture

Status: Postponed (maintainer needs more info) » Needs work
Related issues: +#2724323: UUID Services update user with pass saved in plain text on database
  if (isset($entity->pass)
    && (!('$S$D' == substr($entity->pass, 0, 4)) || preg_match('/^[a-f0-9]{32}$/', $entity->pass))) {
    // Ensure user's password is hashed.
    $entity->pass = user_hash_password($entity->pass);
  }

@skwashd as you (writefully) mentioned in #2724323: UUID Services update user with pass saved in plain text on database, the most frequently used scenario is deploy module (site A) pushing content to services module (site B).

If user password is hashed by site A using default password.inc, user_hash_password() will not be called.

If user password comes as a clear text, function user_hash_password mush exist, so we need to include password.inc

By the way, if site uses non-default hashing algorithm, hashed password will be rehashed again, breaking user passwords

valthebald’s picture

Instead of using hard-coded pattern for hashed password, we can use (swappable) user_needs_new_hash():

  if (isset($entity->pass) && !preg_match('/^[a-f0-9]{32}$/', $entity->pass)) {
    require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
    if (user_needs_new_hash($entity)) {
      $entity->pass = user_hash_password($entity->pass);
    }
  }

with exception for md5()-ed D6 passwords.

osodani’s picture

Ran into this issue today, #6 solved it for us