@gahooa:
this is a great answer! however, you'll definitely want to use an message digest on that password (preferrably with some padding) to make it so that people can't see their username / password clear text.
http://pajhome.org.uk/crypt/md5/scripts.html Here's a great set of JavaScript that will encrypt the information before you send it over the network.
Basically the concept is that you can store the user's password as this encrypted format (also a really good idea) or dynamically compute them if you wish, but after both have been digested they should match.
And then you'd add just 1 function to (gahooa's code):
$.post(
'/login.php',
{username: u, password: hex_md5(p)}, // here
onLogin,
'json'
);
This is not the most secure that you can be, as you could consider doing a salt as well, where you do this:
var salt = '$@.@^-^$'; // any random value with $p3c14l ch@|2$ (special chars)
$.post(
'/login.php',
{username: u, password: hex_md5(hex_md5(p) + salt)}, // here
onLogin,
'json'
);
then in the server-side authentication function you'd do a comparison of the hashed values, i.e.:
<?php
$salt = '$@.@^-^$'; // same as on client-side
function authenticate( $user, $pass ){
...
if( md5( md5( $storedPassword ) . $salt ) == $_POST['username'] ){ ... }
...
}
?>
or, like I said, you could store the already hashed version
md5( md5( $_POST['signup_password'] ) . $salt )
of users' passwords when they sign up (and convert all existing ones)