I assume that you keep passwords clear. This is not only quite unsafe, but in most situations. My advice is to store passwords in two columns, for example:
password_salt VARCHAR(16) password_hash VARCHAR(40)
Before saving a new password, take the user-provided password ( $clear_password ), create a random string ( $salt ) and use both to create a hash ( sha1sum($salt . $clear_password ). Store both the salt and the hash and cancel password clearing.
To verify the password, retrieve the saved salt for this user, generate a hash and see if it matches the hash in the database.
This method is called salty passwords .
Álvaro González
source share