function crumb_validate($crumb, $key, $ttl = 0, $target = '') { list($time, $hash) = explode('-', $crumb); if ($ttl) { $then = $time + $ttl; $now = time(); if ($now > $then) { return 0; } } $base = crumb_get_base($key, $target); $hash_test = crumb_hash($base . $time, 10); $hash = str_split($hash); $hash_test = str_split($hash_test); $len_hash = count($hash); $len_test = count($hash_test); if ($len_hash != $len_test) { return 0; } for ($i = 0; $i < $len_hash; $i++) { if ($hash[$i] != $hash_test[$i]) { return 0; } } return 1; }
function crumb_validate($crumb, $key, $ttl = 0) { $base = crumb_get_base($key); list($time, $hash) = explode('-', $crumb); $hash_test = crumb_hash($base . $time, 10); if ($hash_test != $hash) { return 0; } if ($ttl && $time + $ttl > time()) { return 0; } return 1; }