将用户名和密码发送到身份验证服务器时应考虑哪些最佳实践?
我想知道使用 ajax 向身份验证服务器发送用户名和密码时需要记住哪些事情。我正在使用 PhoneGap 和 jQuery 开发一个 Web 应用程序,我对此非常陌生,我想确保我以正确的方式进行操作。欢迎任何建议。
I'm wondering what sorts of things I need to keep in mind when sending a username and password to an authentication server using ajax. I'm using phoneGap and jQuery to develop a web app, which I'm very new to, and I want to make sure I go about it the right way. Any advice is welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用挑战-响应机制。
服务器应向客户端发送不可重复使用的过期随机数和用户的盐。
客户端应该使用盐对密码进行哈希处理,使用随机数对生成的哈希值进行哈希处理,然后将该哈希值发送回服务器。
服务器应在其数据库中存储预加盐的密码哈希值。
然后,它应该使用随机数对存储的哈希值进行哈希处理,并将其与来自客户端的哈希值进行比较。
这使得攻击者无法得知原始密码,即使攻击者是活跃的中间人并窃取了数据库。
但是,如果攻击者窃取了数据库,他将能够通过绕过您的 UI 并使用已知的哈希来登录。
You should use a challenge-response mechanism.
The server should send the client a non-reusable expiring nonce and the user's salt.
The client should hash the password with the salt, hash the resulting hash with the nonce, and send that hash back to the server.
The server should store pre-salted password hashes in its database.
It should then hash the stored hash with the nonce, and compare that to the hash from the client.
This makes it impossible for an attacker to learn the original password, even if the attacker is an active man-in-the-middle and has stolen the database.
However, if the attacker steals the database, he will be able to login by bypassing your UI and using the known hash.
这是您自己构建的应用程序,还是您将与现有的基于网络的服务对话?
假设 HTTPS 可用,则必须使用 HTTPS。如果您自己构建网站,我建议您研究基于令牌的系统,类似于许多流行网站使用的系统。
基本流程如下:
一般来说,避免以纯文本形式存储用户密码。以与服务器身份验证系统兼容的形式对其进行哈希处理,然后存储该值。
Is this an app you're building yourself, or will you be talking to an existing web-based service?
Using HTTPS is a must, assuming it's available. If you're building the website yourself, I'd recommend looking into a token-based system, similar to those used by many popular websites.
The basic flow goes like this:
In general, avoid storing the user's password in plain text. Hash it in a form that's compatible with the server's authentication system, and then store that value.
我用过雷蒙德的例子。我还在客户端有哈希密码。
http://www.raymondcamden .com/index.cfm/2011/11/10/基于服务器的登录与 PhoneGap 示例
I've used Raymond's examples. Also i've hash password in client side.
http://www.raymondcamden.com/index.cfm/2011/11/10/Example-of-serverbased-login-with-PhoneGap