, . - ( , Java ):
random_number = rand(1000000, 9999999);
secret = "Some random text here";
timestamp = unix_timestamp();
user_ip = users_ip();
setcookie("random_number", random_number);
setcookie("timestamp", timestamp);
setcookie("token", sha256(random_number + secret + timestamp + ip));
, , :
random_number = getcookie("random_number");
secret = "Some random text here";
timestamp = int(getcookie("timestamp"));
user_ip = users_ip();
token = sha256(random_number + secret + timestamp + ip);
if(unix_timestamp() - timestamp < 0 || unix_timestamp() - timestamp > timeout) {
}
if(token == getcookie("token")) {
} else {
}
- , , IP-. timestamp, , . .
, . . ( , " timestamp ip", "ip number timestamp" ..).
, HMAC - , , . .
Hope this helps.
EDIT
It should be noted that your secrets must be the same to verify the work.
source
share