Example 1 — Cost Is Too Low
The stored hash uses cost 7, but we want cost 10.
<?php
$hash = '$2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq';
if (password_needs_rehash($hash, PASSWORD_BCRYPT, ['cost' => 10])) {
echo "Rehash needed", PHP_EOL;
} else {
echo "Hash is current", PHP_EOL;
} How It Works
- Start with a stored hash. Its cost is 7.
- State what you want. bcrypt with cost 10.
- Compare the settings. They are different.
- Get true. The hash should be upgraded.

