I want to improve my login system, by adding "Remember me" function. I actually made it, everything works fine, but now I want to upgrade it, by saving only md5 hashed values to cookies, so users can't edit them. But when I hash the string and store it to cookie and then hash it again, it doesn't return original string, but different hash. Is there any way I can achieve this? Code:
Setting cookie (this works fine):
$userCrypted = md5($_SESSION['username']);
if(!empty($remember)) {setcookie('remember', $userCrypted ,time()+60*60*24*365);}
Using cookie value to extract data from database (this doesn't work):
if(isset($_COOKIE['remember'])) {
$user = $_COOKIE['remember'];
$user = md5($user);
$queryCookie = "SELECT * FROM `users` WHERE `username` = '$user'";
$resultCookie = mysqli_query($link, $queryCookie) or die(mysqli_error($link));
while ($output = mysqli_fetch_object($resultCookie)) {
//data extraction
}