簡體   English   中英

匹配哈希+鹽漬密碼

[英]Matching Hashed + Salted Passwords

我正在學習加密和安全性,我對一個(可能是簡單的)概念感到困惑。

我理解哈希和鹽在大多數情況下是如何工作的,但我不明白函數如何匹配密碼。 例如,以下是passlib文檔的一部分:

>>> # import the hash algorithm
>>> from passlib.hash import sha256_crypt

>>> # generate new salt, and hash a password
>>> hash = sha256_crypt.encrypt("toomanysecrets")
>>> hash
'$5$rounds=80000$zvpXD3gCkrt7tw.1$QqeTSolNHEfgryc5oMgiq1o8qCEAcmye3FoMSuvgToC'

>>> # verifying the password
>>> sha256_crypt.verify("toomanysecrets", hash)
True
>>> sha256_crypt.verify("joshua", hash)
False

在第4行,它提到生成一個新的鹽,但據我所知,鹽永遠不會與密碼一起存儲。

為什么我可以將散列密碼作為字符串存儲在數據庫中,並在以后驗證它而不提供鹽?

根據文件

sha256-crypt哈希字符串的格式$5$rounds=rounds$salt$checksum

salt(在你的情況下是'zvpXD3gCkrt7tw.1' )存儲在字符串本身中 ; 這就是為什么它不需要單獨存儲。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM