I have a PHP7 app which hashes users passwords like this
$hash = password_hash($password, PASSWORD_BCRYPT);
For example, if I pass test1234
to that, I've got:
$2y$10$aazE9OUKZlOQiM6axwxU/utpOURLQ58pluqtFZkkGE3R9ShtUxBOm
Now, I have a Python app, which has to update users passwords too. It uses something like this:
import bcrypt
hash = bcrypt.hashpw(password, bcrypt.gensalt())
As an example, the same password test1234
hashed as:
$2a$12$vsI9Vf9gWj/Au3McYradxuozyZychmlfqoCJcSacDWuMzUDVpv33m
As you can see, PHP generated $2y
where Python did $2a
- so they are a bit different versions of hashes.
Now, if I will try to verify, both Python and PHP hashes, in PHP like this:
$result = password_verify($password, $hash);
I have true
in both cases. But, if I try to verify both on Python side:
bcrypt.checkpw(password, hash)
It only works for when I pass hash generated in Python. If I pass hash generated in PHP, I've got:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid hashed_password salt
My question: is there anything I'm missing?
The bcrypt
module is supplied by the py-bcrypt
project, version 0.4, that I had installed using pip:
pip3 install py-bcrypt