Example 1 — Check a Password
Test a right and a wrong password against a stored hash.
<?php
$hash = '$2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq';
echo password_verify('rasmuslerdorf', $hash) ? "Password is valid" : "Invalid password", PHP_EOL;
echo password_verify('wrong-pass', $hash) ? "Password is valid" : "Invalid password", PHP_EOL; How It Works
- Load the stored hash. It came from
password_hash(). - Pass the typed password. The function reads the salt from the hash.
- Get true for a match. The first call matches.
- Get false for a mismatch. The second call does not.

