What is the meaning of checking hash in the cookie when auto login using PHP

$randomString = 'string';
$hash = md5($id . $randomString . $username);
setCookie('id', $id);
setCookie('username', $username);
setCookie('hash', $hash);

when auto login

if($hash == md5($id . $randomString . $username)){//auto login...}

The question is I retrieve id,username from cookie,and I compare the hash value retrieved from cookie with the two values I retrieved before,it means nothing.They will always be the same,is there any cases that the two value will not be the same?

So what exactly is the meaning of this if statement?For secure consideration?

Answers


They will always be the same unless the setCookie function modifies one of $id, $username or $hash by reference.


Need Your Help

Spark Jaccard similarity computation by min hashing slow compared to trivial approach

scala apache-spark apache-spark-mllib

Given 2 huge list of values, I am trying to compute jaccard similarity between them in Spark using Scala.