function PhpPassword::check

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Password/PhpPassword.php \Drupal\Core\Password\PhpPassword::check()

Check whether a plain text password matches a hashed password.

Parameters

string $password: A plain-text password.

string|null $hash: A hashed password.

Return value

bool TRUE if the password is valid, FALSE if not.

Overrides PasswordInterface::check

File

core/lib/Drupal/Core/Password/PhpPassword.php, line 43

Class

PhpPassword
Secure PHP password hashing functions.

Namespace

Drupal\Core\Password

Code

public function check(#[\SensitiveParameter] $password, #[\SensitiveParameter] $hash) {
  // Prevent DoS attacks by refusing to check large passwords.
  if (strlen($password) > static::PASSWORD_MAX_LENGTH) {
    return FALSE;
  }
  // Newly created accounts may have empty passwords.
  if ($hash === NULL || $hash === '') {
    return FALSE;
  }
  return password_verify($password, $hash);
}

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