function PhpPassword::hash

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Password/PhpPassword.php \Drupal\Core\Password\PhpPassword::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/lib/Drupal/Core/Password/PhpPassword.php, line 31

Class

PhpPassword
Secure PHP password hashing functions.

Namespace

Drupal\Core\Password

Code

public function hash(#[\SensitiveParameter] $password) {
  // Prevent DoS attacks by refusing to hash large passwords.
  if (strlen($password) > static::PASSWORD_MAX_LENGTH) {
    return FALSE;
  }
  return password_hash($password, $this->algorithm, $this->options);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.