Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP password_needs_rehash() Function

PHP password_needs_rehash() Function

PHP Password Hashing AlgorithmsPHP Password Hashing Algorithm

The password_hash() function is used to check whether the hash matches the specified options.

PHP version requirement: PHP 5 >= 5.5.0, PHP 7

Syntax



bool password_needs_rehash ( string $hash , int $algo [, array $options ] )

Parameter Description:

Return Value

This function checks whether the specified hash implements the provided algorithm and options. If not, the hash needs to be regenerated.

Example

password_needs_rehash() Usage

11 ) ; // verify the stored hash against the plaintext password if ( password_verify ( $password , $hash ) ) { // check if there is a newer available hashing algorithm // or if cost has changed if ( password_needs_rehash ( $hash , PASSWORD_DEFAULT , $options ) ) { // if so, create a new hash, replacing the old one $newHash = password_hash ( $password , PASSWORD_DEFAULT , $options ) ; } // log the user in } ?>

PHP Password Hashing AlgorithmsPHP Password Hashing Algorithm