我需要將原始的php auth驗證移動到python3。我有這樣的代碼:PHP Bcrypt移到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";
它與參數做成本= 14
什麼來實現它在python3最好的lib?
編輯: 我使用了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
爲什麼鹽無效?
在PHP它的工作原理:
password=ahoj
hash=$2y$14$00sMXcXPyTthEv9m5dszwuT8VUU6KK1HtCunemfutphrbCHZoIz0e
result=$2y$14$00sMXcXPyTthEv9m5dszwuT8VUU6KK1HtCunemfutphrbCHZoIz0e
什麼是蟒蛇有什麼不同?
這是一個標準的bcrypt散列,任何庫都會處理它。 –