Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Enter the site address here,
- * must include the protocol used and the slash */
- define("SITE_ADDR", "https://localhost/");
- /* This is the key used for the HMAC
- * recommend to use `apg` (http://linux.die.net/man/1/apg)
- * or `openssl rand` to generate storng password */
- define("MAC_KEY", "Put something random here");
- /* This defined how long will the URL expire
- * Unit: Seconds
- * Default: 1 Hour */
- define("EXPIRE_TIME", 60*60);
- function GenerateURL($email) {
- $ttl = time() + EXPIRE_TIME;
- $email_hash = hash("md5", $email); //can use urlencode to replace hashing
- $hmac = hash_hmac("sha256", $email_hash.$ttl, MAC_KEY);
- $query = "op=activate&id=$email_hash&expires=$ttl&signature=$hmac";
- return SITE_ADDR . "register.php?$query";
- }
- function VerifyURL($email_hash, $ttl, $hmac) {
- if($ttl < time()) { //Check is the link expired
- return false;
- } elseif($hmac != hash_hmac("sha256", $email_hash.$ttl, MAC_KEY)) { //Check the link signature
- return false;
- } else {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment