Email PPR
This commit is contained in:
@@ -90,4 +90,38 @@ function require_auth() {
|
||||
echo 'Text to send if user hits Cancel button';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function generateSecureToken($email, $entryId) {
|
||||
$secretKey = "your-very-secret-key"; // Use an environment variable for this
|
||||
$timestamp = time();
|
||||
$data = "$email|$entryId|$timestamp";
|
||||
$hash = hash_hmac('sha256', $data, $secretKey);
|
||||
return base64_encode("$data|$hash");
|
||||
}
|
||||
|
||||
|
||||
function validateSecureToken($token) {
|
||||
$secretKey = "your-very-secret-key";
|
||||
$decoded = base64_decode($token);
|
||||
|
||||
if (!$decoded) return false;
|
||||
|
||||
list($email, $entryId, $timestamp, $hash) = explode('|', $decoded);
|
||||
|
||||
// Check expiration (e.g., valid for 1 hour)
|
||||
if (time() - $timestamp > 3600) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify hash
|
||||
$data = "$email|$entryId|$timestamp";
|
||||
$validHash = hash_hmac('sha256', $data, $secretKey);
|
||||
|
||||
if (!hash_equals($validHash, $hash)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ['email' => $email, 'entryId' => $entryId];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user