Je dois déplacer la vérification d'origine php auth vers python3. J'ai le code comme ceci:PHP Bcrypt passer à Python3
// hash from db
$hash = "$2y$14$00sMXcXPyTthEv9m5dszwuT8VUU6KK1HtCunemfutphrbCHZoIz0e";
// the hash is used as salt
$result = crypt($password, $hash);
//result should match the hash if pasword is correct
$result = "$2y$14$00sMXcXPyTthEv9m5dszwuT8VUU6KK1HtCunemfutphrbCHZoIz0e";
Il est fait avec un coût de paramètre = 14
Quelle est la meilleure lib pour la mettre en œuvre dans python3?
EDITED: J'ai utilisé lib py-bcrypt.
>>> import bcrypt
>>> password = "ahoj"
>>> db_hash = "$2y$14$00sMXcXPyTthEv9m5dszwuT8VUU6KK1HtCunemfutphrbCHZoIz0e"
>>> computed_hash = bcrypt.hashpw(password, db_hash)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid salt
Pourquoi le sel est-il invalide?
En PHP, il fonctionne:
password=ahoj
hash=$2y$14$00sMXcXPyTthEv9m5dszwuT8VUU6KK1HtCunemfutphrbCHZoIz0e
result=$2y$14$00sMXcXPyTthEv9m5dszwuT8VUU6KK1HtCunemfutphrbCHZoIz0e
Ce qui est différent en python?
C'est un hachage bcrypt standard, toute bibliothèque le gérera. –