admin管理员组文章数量:1193758
just to know, is it possible to send password through an Ajax request safely?
I've a login box that calls an ajax request to try the login/pass and retrieve a JSON Object with errors (if any).
Should I use a form redirection instead?
[EDIT] Store the encrypted password in the database isn't the solution because the login and password send by ajax are the login / password to access the database itself (internal application).
just to know, is it possible to send password through an Ajax request safely?
I've a login box that calls an ajax request to try the login/pass and retrieve a JSON Object with errors (if any).
Should I use a form redirection instead?
[EDIT] Store the encrypted password in the database isn't the solution because the login and password send by ajax are the login / password to access the database itself (internal application).
Share Improve this question edited Oct 23, 2010 at 10:30 Arnaud F. asked Oct 23, 2010 at 9:33 Arnaud F.Arnaud F. 8,45212 gold badges57 silver badges104 bronze badges4 Answers
Reset to default 14The only way to send something that can not be intercepted by a third party is by using HTTPS instead of regular HTTP. That way everything sent between the server and the client is strongly encrypted.
For the technical hell of it, you can. If you have access to a one-way cryptographic function crypt(text,key)
that supports crypt(crypt(T,A),B) == crypt(crypt(T,B),A)
you can do the following:
- Have a secret key for your application,
KEY
. Never tell anyone. - When the user registers, store
crypt(password,KEY)
in the database. - When the user wants to log in, send them a randomly generated key
RAND
- The user types the password, the form computes and sends
crypt(password,RAND)
through unsecure AJAX. The password never leaves the user's computer. - The server computes
crypt(crypt(password,RAND),KEY)
from the form response,crypt(crypt(password,KEY),RAND)
from the database, and compares the two. They should be equal.
All of this is unnecessary complicated an requires a lot of effort to implement correctly and securely. Buying an SSL certificate and using HTTPS is orders of magnitude easier to achieve this level of security, and even more.
Here's what you could do:
Hash Password and store in database
On client side: hash password, then add salt (concatenate session_id string), then hash again
On server: take hashed pw from database, then add salt (concatenate session_id string), then hash again
[Edit: and then compare the hash-salt-hash generated on the server with the one sent from the client]
Intercepting your hash-salt-hash password is quite useless now, because it is only valid for that particular session...
What you're looking for is a "zero knowledge protocol". It is a way of communicating that you know a password without sending it. You would communicate between the javascript running in the user's browser, and the server.
Bonus, these protocols are generally secure even if the connection isn't encrypted. Note that it would be stupid to rely on this and not use SSL, because a man in the middle would simply replace your nice zero knowledge protocol implementation with a look-alike function that just sends the password.
本文标签: javascriptSend password safely using an ajax requestStack Overflow
版权声明:本文标题:javascript - Send password safely using an ajax request - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738448887a2087369.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论