如何验证和验证密码?
我真的不知道在这里要问什么问题。我的问题陈述很简单:我需要使用盐在数据库上存储密码,根据存储的密码验证输入的密码,并在用户尝试登录时使用随机质询词对密码进行身份验证。我正在使用 php/javascript。
在试图解决这个问题时,我遇到的问题是,如果我以 html 形式传递挑战词,然后用该词对输入的密码进行哈希处理,我可以在服务器上验证密码,但我无法分离来自挑战词的密码,这样我就可以根据数据库上的加盐密码验证它。如果我将密码以明文形式发送到服务器或在没有挑战词的情况下对其进行哈希处理,我可以验证它,但现在我无法可靠地验证它。
我想我需要某种双向算法,这样我就可以用密钥对其进行加密,然后在验证密码的同时验证密钥。我该怎么做?或者如果做不到那我应该做什么?
I don't really know even what questions to ask here. My problem statement is simple: I need to store a password on the DB with a salt, validate an entered password against the stored password, and authenticate the password using a random challenge word whenever a user tries to log on. I am using php/javascript.
In trying to figure this out, the problem I am having is that if I pass up a challenge word in an html form, then hash the entered password with that word, I can authenticate the password on the server, but I can not separate the password from the challenge word so I can validate it against the salted password on the DB. If I send the password to the server in the clear or hash it without a challenge word, I can validate it but now I can not reliably authenticate it.
I think I need a 2 way algorithm of some sort so I can encrypt it with a key, and then authenticate the key while validating the password. How do I do it? or if it can't be done then what should I be doing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用客户端脚本加密密码通常是一个坏主意。执行此操作的正确方法是使用 SSL。
另外,绝不以明文形式存储密码。如果您必须使用上述方法,请对密码进行两次哈希处理:一次用于将其存储在数据库中,另一次用于双向身份验证。
Encrypting a password with client-side scripting is generally a bad idea. The proper way to do this is to use SSL.
Also, never store password in cleartext. If you must use a method like the one you describe above, hash the password twice: once for storing it in the database, another time for the two-way authentication.
要存储密码,请生成随机盐。存储
HASH(密码+盐)
和盐
。 (服务器或客户端都可以执行此计算。)要执行身份验证,服务器会查找
salt
和HASH(password+salt)
。然后,它生成一个随机质询,并将盐和质询发送给客户端。在客户端上,提示用户输入密码。计算:
HASH( HASH(密码+盐) + 质询)
。将其发送到服务器。在服务器上,您已经有了
HASH(password+salt)
并且您有挑战
。因此您还可以计算:HASH( HASH(password+salt) +challenge)
。将其与客户发送给您的内容进行比较。如果它们匹配,则密码正确。请注意,这很容易受到 MITM 攻击,因此应通过本身受 MITM 保护的连接(例如 SSL 连接)使用它。
To store a password, generate a random salt. Store
HASH(password+salt)
andsalt
. (Either the server or the client can do this computation.)To perform an authentication, the server looks up the
salt
andHASH(password+salt)
. It then generates a random challenge and sends the salt and the challenge to the client.On the client, prompt the user for the password. Compute:
HASH( HASH(password+salt) + challenge)
. Send it to the server.On the server, you already have
HASH(password+salt)
and you havechallenge
. So you can also compute:HASH( HASH(password+salt) + challenge)
. Compare this to what the client sent you. If they match, the password is correct.Note that this is vulnerable to a MITM attack, so it should be used over a connection that is itself protected from a MITM, such as an SSL connection.