Skip to content Skip to sidebar Skip to footer

Salt And Crypt Assistance

i got my login page, and on it I am also using it to autheticate both username and password. im stuck on checking the password against that provided in the database. This is becaus

Solution 1:

// let the salt be automatically generated$hashed_password = crypt('mypassword'); 

// You should pass the entire results of crypt() as the salt for comparingif (crypt($user_input, $hashed_password) == $hashed_password) {
   echo"Password verified!";
}

EDIT

crypt() takes two paramaters, and second is so called salt (see wiki). If not provided, salt will be autogenerated (hence can be considered random). Salt is used in the whole alghorithm, therefore to compare you want to crypt() user provided password with the same salt you did before otherwise result will be different. To make this possible salt is added to crypt result (at the begining) so providing previous result for comparion purposes simply feeds crypt() with old salt (it is either 2 or 12 chars depending on alghoritm used).

Post a Comment for "Salt And Crypt Assistance"