Bit complicated, but it is like this:
To start with, you don't want to save the users password in the DB as plain-text, so you encrypt it with a a one-way hashing algorithm like MD5 or SHA256. Using a server-side script (like PHP) you can encrpyt the users password with a constant seed, and store that hashcode in the DB (Now no one who can read your DB can get any passwords). The constant seed must remain constant through out the life of your application.
Note that the password CANNOT be decrypted, because it is a One-Way algorithm, but we won't need to decrypt it, only compare against it!
Now when you first send the client the page with the login form from the server, you should add a constant seed and random seed to the page via PHP output, as they will be required when encrypting the client-side password. Also, store the Random seed for later use, it will be needed.. This is best stored in a Session Variable, as it only lasts the life of the users session.
Then, when the users goes to login, you must encrypt the password on the clients machine (using JavaScript) always with the same a one-way hashing algorithm used for the server-side hashcode. The best way is to encrypt twice; first with the constant seed, and then with the randomly generated seed, both of which were added to the page via PHP Output.
Once that is done, the client can send that hashcode to the server (it is safe now), but the server has to recognize it, so the next step is to verify the hashcode sent from the client.
To do this, we get the original hashcode stored in the DB (if you recall, it was only encrypted once, with the constant seed), and then use the random seed we generated earlier (it should be stored in a session variable) and we use those to encrypt the hashcode (now encrypted with both the constant and random seeds), so that the resulting hashcode is the REAL hashcode, and the hashcode that was sent from the client (over the internet) is the clients attempt at the password. If the two hashcodes match, then the user entered the right password!
I hope that makes sense to you.. any questions, fire away!!
Thanks for the reply. But I'm not really clear on what you mean by 'seed'. you mentioned that I need a constant seed and a random seed. by 'seed' do you mean a hash or encryption? could you clearify that for me. thank you