You must first create a random user salt. Then you must store this and the password hash in the database.
$salt = md5(unique_id().mt_rand().microtime()); $pass = sha1($salt.$_REQUEST['pass']);
and save $ salt and $ pass in the database. Then, when they log in, you look at their line and check the hash:
$user = query('SELECT * FROM `user` WHERE username = ?', array($_REQUEST['username'])); if($user) { // If the password they give maches if($user->pass === sha1($user->salt. $_REQUEST['pass'])) { // login } else { // bad password } } else { // user not found }
Creating custom salt for each account ensures that rainbow tables are useless, and anyone who breaks down on your server would have to go overboard with every password.
Xeoncross
source share