Correct, right now, I'm saving the password as plain text on the
server. When the user signs in their password is sha1 hashed by
javascript then sent to the server where the server password is then
sha1 hashed and compared to what the client sent.
So what your proposing is when the user signs up, hash the password as
usual, but save it in that state to the server.
Then when the user signs in, hash their password, send to the server
and then compare? Wouldn't that be sending the same hash to the server
each time, how's the better then just sending plain text? that is
plain text in essence...
your instinct is spot on, sending the same hash each time would be
what I earlier referred to as a "password equivalent" which is why
that's NOT what Bart is suggesting.
Look at the code he points to, it uses a salt.
Client C requests login page
Server S sends login page, with md5.js and sha1.js - _and_ in hidden
input or wherever, a random salt, server also stores salt in session
C inputs password and presses submit, the javascript md5(p) and
concatenates the salt and then sha1( md5(p) + salt ), blanks the
password field(so the plain text isnt sent) and sends hashed
password_data to server
server knows what salt it sent earlier so S just retrieves the
password from the database which is stored in some hashed form (lets
say as md5), so dbpass = md5(p)
then S knows that if $_POST['password_data'] == sha1(dbpass + salt)
then the user must have typed the good password
Server then immediately deletes the salt from the session, so that a
replay attack cannot occur from a passive sniffer (man-in-the-middle)
reposting the same data.
Notice at no point is the actual password stored, instead it is stored
in the database as md5 hash.
This is so if anyone steals any data they cannot obtain the password,
since md5, like sha1 is irreversible.
Also you dont have to use md5 in database, you could use sha1 in the
database, so now the client just needs to be sent
sha1.js and can do sha1( sha1(p) + salt)
and server checks to see if this is equal to
sha1( $_POST['password_data'] + salt )
This is what I referred to as multiple hashing - using same algo,
which is super fast and in fact you can hash a few times if you wish,
as long as the server and client agree on how many times that was.
What you have to understand is that none of this helps you when
*changing* the password. Because when you change the password the
server has no stored password hash in the database, for this you need
assymetirc (reversible) encryption as dicussed earlier.