我需要将原始的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散列,任何库都会处理它。 –