2017-03-06 128 views
1

我想擁有一種驗證用戶身份(引入他的密碼)的方式,而不需要以純文本格式存儲該密碼,甚至不需要密碼。如何安全地存儲沒有哈希的密碼?

我應該怎麼做?

有一個控制字符串,用戶密鑰可以加密並將其與我存儲的加密字符串進行比較是否安全?

+0

「沒有以明文形式存儲該密碼或者甚至是散列密碼」 - 爲什麼? – mayersdesign

+0

安全原因 – jm8FE

+1

哈希算法是不是工作? –

回答

1

每NIST(美國國家標準與技術研究所):

使用散列函數,遍歷一個HMAC與隨機鹽約100ms的持續時間和保存鹽與哈希值。使用功能如PBKDF2,password_hash,Bcrypt和類似的功能。關鍵是要讓攻擊者花費大量時間通過強力查找密碼。

參見:How to store your users’ passwords safely

從表示「走向更好的密碼要求」摘錄由吉姆·芬頓 信息基於NIST SP 800-63-3文件草案「數字認證指南」

務必:

Require an 8 character min, >64 max with no truncation or 6 random digits 
Use a dictionary to disallow common passwords against a dictionary list of 10M compromised passwords 
Allow all printing characters (Unicode optional) + spaces but MAY canonicalize spaces out 
Best to accept Unicode, including emojis (1 「character」/code point) 
Limit failed authentication attempts to 100 in 30-day period per account 
Offer option to display the secret while typing rather than dots or asterisks 

Storing passwords: 
    Hash with 32-bit random salt using key derivation function such as 
    PBKDF2 with SHA-1, SHA-2 family, SHA-3 family 
    with at least 10,000 iterations 

別T:

Require composition rules 
Allow hints 
Require routine password expiration 
Save plain or hashed versions with or without seeding 

見:Toward Better Password Requirements由吉姆·芬頓。

1

請參閱Zaph的回答你需要做什麼。如果有幫助,我會添加更多背景。

事實證明,以加密形式存儲密碼不如存儲正確完成的密碼哈希安全。這是因爲加密密碼被設計爲使用正確的密鑰未加密,並且加密算法不一定依賴於作爲防止強力攻擊的防禦措施之一緩慢。

但是一個正確完成的密碼哈希算法的設計使得您無法從哈希中獲得密碼,並且密碼哈希算法設計會使用哈希速度(即使其變慢)作爲對嘗試進行部分防禦通過對每個可能的密碼進行蠻力散列來找到密碼。

相關問題