CKTIS / PHP
password_needs_rehash()
Compare a stored password hash with the requested algorithm and cost settings.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
password_needs_rehash(string $hash, string|int|null $algo, array $options = []): boolCompare a stored password hash with the requested algorithm and cost settings. A mismatch yields true without checking any password. After successful password verification, use the supplied password to generate and store the replacement hash.
Signature
password_needs_rehash(string $hash, string|int|null $algo, array $options = []): bool
Example output
[false,true]
Examples
<?php
$stored=password_hash("maple notes",PASSWORD_BCRYPT,["cost"=>12]);
echo json_encode([password_needs_rehash($stored,PASSWORD_BCRYPT,["cost"=>12]),password_needs_rehash($stored,PASSWORD_BCRYPT,["cost"=>13])]);
Result
[false,true]