如何安全地存储没有哈希的密码?

问题描述:

我想拥有一种验证用户身份(引入他的密码)的方式,而不需要以纯文本格式存储该密码,甚至不需要密码。如何安全地存储没有哈希的密码?

我应该怎么做?

有一个控制字符串,用户密钥可以加密并将其与我存储的加密字符串进行比较是否安全?

+0

“没有以明文形式存储该密码或者甚至是散列密码” - 为什么? – mayersdesign

+0

安全原因 – jm8FE

+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由吉姆·芬顿。

请参阅Zaph的回答你需要做什么。如果有帮助,我会添加更多背景。

事实证明,以加密形式存储密码不如存储正确完成的密码哈希安全。这是因为加密密码被设计为使用正确的密钥未加密,并且加密算法不一定依赖于作为防止强力攻击的防御措施之一缓慢。

但是一个正确完成的密码哈希算法的设计使得您无法从哈希中获得密码,并且密码哈希算法设计会使用哈希速度(即使其变慢)作为对尝试进行部分防御通过对每个可能的密码进行蛮力散列来找到密码。