Forum Moderators: phranque
if ($_COOKIE['user'] && $_COOKIE['pass']) {
$welcome = 'welcome ' . $_COOKIE['user'];
$sth_user = sprintf("SELECT COUNT(1) FROM pm WHERE username = '%s'",
mysql_real_escape_string($_COOKIE['user']));
list($counter) = mysql_fetch_row(mysql_query($sth_user));
$welcome_count = 'You have mail: Inbox ' . $counter;
} What you should be doing here is something like using signed sessions tied in the back end to a user, or at least adding a signature cookie (e.g. a salted hash) to check the username is not a fake.
Why do you have a password cookie? You only need the password at login, to compare against the (hopefully hashed) value in your DB.
But either way I would still have to run a query to compare the stored hash to the database to get the actual username, right?
Right now I'm leaning towards a BASE64 encryption on the username .... then I could just decrypt it instead of running another query on every page.
Base64 is not encryption.
I would still have to run a query to compare the stored hash to the database to get the actual username, right?
Its generally a bad idea to write your own authentication. Use a library or framework.
The difference being that a BASE64 encoded string can be converted back to plain text (ascii) by anyone. An encrypted value can only be converted back to plain text if one knows the encryption key.