interface PasswordInterface (View source)

Secure password hashing functions for user authentication.

Constants

PASSWORD_MAX_LENGTH

Maximum password length.

Methods

string
hash(string $password)

Hash a password using a secure hash.

bool
check(string $password, string $hash)

Check whether a plain text password matches a hashed password.

bool
needsRehash(string $hash)

Check whether a hashed password needs to be replaced with a new hash.

Details

string hash(string $password)

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.

bool check(string $password, string $hash)

Check whether a plain text password matches a hashed password.

Parameters

string $password

A plain-text password

string $hash

A hashed password.

Return Value

bool

TRUE if the password is valid, FALSE if not.

bool needsRehash(string $hash)

Check whether a hashed password needs to be replaced with a new hash.

This is typically called during the login process when the plain text password is available. A new hash is needed when the desired iteration count has changed by a modification of the password-service in the dependency injection container or if the user's password hash was generated in an update like user_update_7000() (see the Drupal 7 documentation).

Parameters

string $hash

The existing hash to be checked.

Return Value

bool

TRUE if the hash is outdated and needs rehash.