It is possible to do this via Ajax by using multiple tools. I have personally done this for the logon of a database app. Unfortunately, I don't know of a single solution to accomplish this. And ultimately, the best solution is to use a SSL certificate. But I have seen times when you need to stand up an app securely before having the SSL in place.
Bcrypt is definitely the more secure way to store a password in a users database, but this applies to the backend, not so much the Ajax part. If you were to use Bcrypt in the client/browser, the encrypted string is still being passed over the internet insecurely.
The solution I recently built uses RSA encryption and AES encryption between the browser (in JavaScript) and the server (in my case, an ASP.NET site).
The flow works like this:
- Client asks server for RSA public key.
- Server sends back RSA public key and keeps RSA private key.
- Client creates an AES key and encrypts it with the RSA public key.
- Encrypted AES key is sent back to server and kept in memory.
- Now Ajax messages can be transmitted both ways securely.
- Each side now securely knows the AES key for encrypting and decrypting.
I wish there was a one-stop solution to do all of this, but I'm unaware of one at this time.
The libraries I used are:
- https://code.google.com/p/crypto-js/
- http://www.bouncycastle.org/csharp/
- http://bcrypt.codeplex.com/