【问题标题】:Why does this passlib hashing script create a new result every time I run the script?为什么这个 passlib 散列脚本每次运行脚本时都会创建一个新结果?
【发布时间】:2016-12-20 12:46:07
【问题描述】:

我正在使用以下script from the passlib docs 来散列密码:

# import the hash algorithm                                                         
from passlib.hash import sha256_crypt                                               

# generate new salt, and hash a password
hash = sha256_crypt.encrypt("toomanysecrets")
print hash  # <== WHY IS THIS ALWAYS A DIFFERENT STRING?
# verifying the password
print sha256_crypt.verify("toomanysecrets", hash)  # Outputs "True"
print sha256_crypt.verify("joshua", hash)  # Outputs "False"

sha256_crypt.verify 能够将多个不同的哈希验证为“toomanysecrets”,这似乎很奇怪——为什么这个密码没有一个哈希?

【问题讨论】:

  • generate new salt

标签: python hash passwords salt passlib


【解决方案1】:

哈希结果取决于输入和salt。其中盐 - 它是随机生成的值,与散列结果一起包含在输出字符串中。这就是为什么每次调用 sha256_crypt.encrypt 输出字符串看起来是随机的,但密码验证能力被保留了。

【讨论】: