11-01-2009, 07:43 PM
|
#12 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
Whoops, that code was not made correctly. I was going for something similar to the following.
PHP Code:
function rand_string($length = 8) {
// Store the random string. $str = '';
for ($n = 0; $n < $length; $n++) { switch(rand(0,2)) { case 0: $str .= chr(rand(65, 90)); break;
case 1: $str .= chr(rand(97, 122)); break;
case 2: $str .= chr(rand(33, 64)); break; } }
return $str; }
// Now when a new user is created we should // give them a hash alongside the password. $pass = $_POST['password']; $salt = rand_string(rand(8,16));
$hash = sha265($salt . $pass);
// Now store it in the database. // This is a dummy function that would store // the value in the correct field/row. // Note: The $user_id would be generated from // another part of the script. $mysql->insert(array('id','password'), array($user_id, $hash));
Now, we would create another unique random string and assign/store it in the database that could be used in a cookie. That would associate the cookie with the correct user account.
|
|
|
|