I have password hashes stored in a Postgresql database generated with:
password_hash($password, PASSWORD_DEFAULT);
Now I would like to also be able to verify a user password with Postgresql and pgcrypto.
But pgcrypto's crypt()
function is not able to verify the existing password hashes.
However - I can verify password hashes generated by Postgresql with PHP's password_verify
.
For example:
password_hash('hello', PASSWORD_DEFAULT);
$2y$10$fD2cw7T6s4dPvk1SFHmiJeRRaegalE/Oa3zSD6.x5WncQJC9wtCAS
postgres=# SELECT crypt('hello', gen_salt('bf'));
crypt
--------------------------------------------------------------
$2a$06$7/AGAXFSTCMu9r.08oD.UulYR0/05q7lmuCTC68Adyu/aNJkzpoIW
Verification:
// php_verify with the Postgresql hash
php > var_dump(password_verify('hello', '$2a$06$7/AGAXFSTCMu9r.08oD.UulYR0/05q7lmuCTC68Adyu/aNJkzpoIW'));
bool(true)
postgres=# SELECT crypt('hello', '$2y$10$fD2cw7T6s4dPvk1SFHmiJeRRaegalE/Oa3zSD6.x5WncQJC9wtCAS');
crypt
---------------
$2JgKNLEdsV2E
(1 Zeile)
My questions are basically:
- Am I doing it wrong?
- If this is not possible: Is there a migration path to make this possible?