= 5.5.0, PHP 7 Syntax bool password_needs_rehash ( string $h" />
English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Password Hashing Algorithm
The password_hash() function is used to check if the hash value matches the specified options.
PHP Version Requirement: PHP 5 >= 5.5.0, PHP 7
bool password_needs_rehash ( string $hash , int $algo [, array $options ] )
Parameter Description:
This function checks if the specified hash value has implemented the provided algorithm and options. If not, the hash value needs to be regenerated.
<?php
$password = 'rasmuslerdorf';
$hash = '$2y$10$YCFsG6elYca568hBi2pZ0.3LDL5wjgxct1N8w/oLR/jfHsiQwCqTS';
// The cost parameter can be modified again when the hardware performance is improved
$options = array('cost' => 11);
// Verify the stored hash according to the plain text password
if (password_verify($password, $hash)) {
// Check if there are any updated hash algorithms available
// or the cost changes
if (password_needs_rehash($hash, PASSWORD_DEFAULT, $options)) {
// If so, create a new hash to replace the old hash
$newHash = password_hash($password, PASSWORD_DEFAULT, $options);
}
// Enables user login
}
?>