what is the securest way to do a "stay logged in" feature?
i think thinking of user logs in store their userid, timestamp and a hash of timestamp + salt + hash of their pw
in a cookie. then when they visit the site next, check if a hash of the cookie timestamp + salt + hash of their pw
is valid
(ie... (untested, and ignore lack of mysql_real_escape_string())
(this is in php)
/*
cookie contains these fields:
username
timestamp
hash
*/
$row = mysql_fetch_array($result);
## sql would be something like select salt,
## username from users where user = $_COOKIE['username']
$generated_cookie_data = my_hash_func(
$_COOKIE['timestamp'] .
$row['salt_from_db'] .
my_hash_func([$row['password'])
)
if ($generated_cookie_data == $_COOKIE['hash']) {
#logged in!
}
else {
#not logged in!
}