Email PPR

This commit is contained in:
2025-03-07 18:38:47 +00:00
parent 5077445d5d
commit 2b7d3e5d2a
3 changed files with 255 additions and 3 deletions

View File

@@ -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];
}