2016-08-13 93 views
0

我使用以下script from the passlib docs哈希密碼:爲什麼這個passlib哈希腳本每次運行腳本時都會創建一個新結果?

# 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」 - 爲什麼沒有這個密碼只有一個哈希?

+0

'生成新鹽' –

回答

2

哈希結果取決於輸入和salt。鹽的位置 - 它是隨機生成的值,與散列結果一起包含在輸出字符串中。這就是爲什麼每次調用sha256_crypt.encrypt的輸出字符串看起來都是隨機的,但密碼驗證能力是保留的。

相關問題