PHP, MySQL - My own version of SALT (I call salty) - Login Issue -
ok wrote own version of salt call salty lol don't make fun of me.. anyway registration part of script follows working 100% correctly.
//generate salty own version of salt , likes me salt.. lol function rand_string( $length ) { $chars = "abcdefghijklmnopqrstuwxyzabcdefghijklmnopqrstuwxyz1234567890"; $size = strlen( $chars ); for( $i = 0; $i < $length; $i++ ) { $str .= $chars[ rand( 0, $size - 1 ) ]; } return $str; } $salty = rand_string( 256 ); //generate salty pw $password = crypt('password'); $hash = $password . $salty; $newpass = $hash; //insert data in database include ('../../scripts/dbconnect.php'); //update db record salty pw ;) // tested , without salty //hence $password , $newpass mysql_query("update `register` set `password` = '$password' `emailinput` = '$email'"); mysql_close($connect); however login script failing. have setup test , echo if login or not. returns failed. entered db , changed crypted salty pw "test" , got success. problem somewhere in login script assume. not sure how implement $salty in this. advised without salty (just using crypt store pass) - still unable perform login successfully. , if you're gonna suggest use blowfish - note webhost doesn't have supported , don't know how install it.
here's login script:
if (isset($_post['formsubmitted'])) { include ('../../scripts/dbconnect.php'); $username = mysql_real_escape_string($_post['username']); $password = crypt(mysql_real_escape_string($_post['password'])); $qry = "select id register emailinput='$username' , password='$password'"; $result = mysql_query($qry); if(mysql_num_rows($result) > 0) { echo 'success'; //start session } else { echo 'failed'; //you not logged in } } so what's wrong login? why isn't working using crypt/storing crypt?
how can make work storing both crypt , randomly generated salty :) ?
ty advance
i make following tweaks code:
function rand_string( $length ) { // added period , slash alphabet $chars = "abcdefghijklmnopqrstuwxyzabcdefghijklmnopqrstuwxyz1234567890./"; $size = strlen( $chars ); for( $i = 0; $i < $length; $i++ ) { $str .= $chars[ rand( 0, $size - 1 ) ]; } return $str; } // need 22 random characters $salty = rand_string(22); // apply blowfish cost := 13 $newpass = crypt($password, sprintf('$2y$%02d$%s', 13, $salty)); this uses blowfish hash password; takes 0.5s complete @ strength 13, depending on situation may want lessen it; cost can changed newer passwords.
the salt stored password btw, there's no need have column that.
to verify password database have first load password field respective register row.
if (crypt($_post['password'], $password_from_db) === $password_from_db) { // success } else { // password didn't match } btw, comparison function turned constant time algorithm prevent timing attacks.
your salty() function can replaced following equivalent produce 22 char long salts:
substr(strtr(base64_encode(openssl_pseudo_random_bytes(18)), '+', '.'), 0, 22); see also: https://wiki.php.net/rfc/password_hash
Comments
Post a Comment