#Initial generation
hashed = bcrypt.hashpw(password, bcrypt.gensalt())
#Store hashed in your db
#Load hashed from the db and check the provided password
if bcrypt.hashpw(password, hashed) == hashed:
print "It matches"
else:
print "It does not match"
import bcrypt
password = u'foobar'
salt = bcrypt.gensalt()
password_hashed = bcrypt.hashpw(password, salt)
# store 'password_hashed' in a database of your choosing
文件中没有提到储存盐,只是说你必须:
http://www.mindrot.org/projects/py-bcrypt/
稍后,假设您有一个用户输入密码
user_pass
。你也可以将其散列,然后将散列与存储的散列进行比较,如果它们匹配,那么原始密码也匹配。注意,bcrypt会自动将salt值存储为散列密码的一部分,以便在将来散列输入时也可以使用它。
第一次:
以后的时间:
使用py bcrypt,不需要单独存储盐:
bcrypt
将盐存储在散列中。您可以简单地将散列用作盐,盐存储在散列的开头。
相关问题 更多 >
编程相关推荐