我有一个python脚本,它将用户数据导入到mongodb中,它使用bcrypt来散列用户的密码。
来自mongodb的数据也将在node.js web应用程序中使用,什么是确保py-bcrypt生成的散列相同的正确方法!
在运行node.js版本时,我得到了这样的结果:
> bcrypt.genSalt(10, function(err, salt) {
... bcrypt.hash("a", salt, function(err, hash) {
..... console.log(hash);
..... });
... });
undefined
> $2a$10$tOT8MN1.3gsb6jWVL2hMRe0PHnJnXCxJX9xBewNl.2iRDnZCV/NeC在python中
>>> import bcrypt
>>> password =b"a"
>>> hashed = bcrypt.hashpw(password, bcrypt.gensalt(10))
>>> hashed
'$2a$10$RzKqQppa3Y7ZZV8f7Ay5COFB5GMEGu7aLH7Fe2HchCyYF1gWVMZ/m'使用node生成的散列比较python中的散列,返回:
>>> node_hash = b"$2a$10$tOT8MN1.3gsb6jWVL2hMRe0PHnJnXCxJX9xBewNl.2iRDnZCV/NeC"
>>> if bcrypt.hashpw(password, node_hash) == node_hash:
... print("It Matches!")
... else:
... print("Does not match")
...
It Matches!有没有办法在python中创建一个用于node.js应用程序的bcrypt哈希?
发布于 2014-08-06 16:14:11
是的,和在Node中一样,传入散列作为第二个参数进行检查。用不同的随机盐创建一个不应该匹配。
https://stackoverflow.com/questions/25155194
复制相似问题