You are here

public function MigratePassword::hash in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/MigratePassword.php \Drupal\user\MigratePassword::hash()

Hash a password using a secure hash.

Parameters

string $password: A plain-text password.

Return value

string A string containing the hashed password, or FALSE on failure.

Overrides PasswordInterface::hash

File

core/modules/user/src/MigratePassword.php, line 58
Contains \Drupal\user\MigratePassword.

Class

MigratePassword
Replaces the original 'password' service in order to prefix the MD5 re-hashed passwords with the 'U' flag. The new salted hash is recreated on first login similarly to the D6->D7 upgrade path.

Namespace

Drupal\user

Code

public function hash($password) {
  $hash = $this->originalPassword
    ->hash($password);

  // Allow prefixing only if the service was asked to prefix. Check also if
  // the $password pattern is conforming to a MD5 result.
  if ($this->enabled && preg_match('/^[0-9a-f]{32}$/', $password)) {
    $hash = 'U' . $hash;
  }
  return $hash;
}