Toad License Key And Site Message «Deluxe»
// Validate license key + domain public function validateLicense($rawKey, $domain) $keyHash = hash('sha256', $rawKey); $stmt = $this->pdo->prepare(" SELECT status, expires_at FROM licenses WHERE license_key_hash = ? AND domain = ? "); $stmt->execute([$keyHash, $domain]); $license = $stmt->fetch(PDO::FETCH_ASSOC);
public function __construct($pdo) $this->pdo = $pdo;
else http_response_code(400); echo json_encode(['error' => 'Invalid action']);
// API Routing $manager = new ToadLicenseManager($pdo); $action = $_GET['action'] ?? ''; Toad License Key And Site Message
elseif ($action === 'get_message') echo json_encode($manager->getActiveMessage());
verifyLicense(); </script> </body> </html> | Feature | Implementation | |--------|----------------| | License key storage | SHA-256 hash, never plaintext | | Domain binding | Prevent key reuse across different sites | | Expiry check | Server-side datetime comparison | | Message injection | Use parameterized queries (already done) | | API abuse | Add rate-limiting (e.g., 5 req/min per IP) | | Admin auth | Add login session / API token for admin routes | 6. Example License Key Generation (for admin CLI) function generateToadKey($domain, $expiryDate) $secret = "TOAD_SECRET_SALT"; // keep secret $payload = $domain . $expiryDate . $secret; $hash = substr(hash('sha256', $payload), 0, 16); return "TOAD-" . strtoupper(substr($domain,0,4)) . "-" . $hash;
return ['valid' => true, 'expires_at' => $license['expires_at']]; // Validate license key + domain public function
3.1 Add/Edit License (admin only) // admin_license.php if ($_POST['add_license']) $rawKey = $_POST['license_key']; $domain = $_POST['domain']; $expires = $_POST['expires_at']; // YYYY-MM-DD HH:MM:SS $keyHash = hash('sha256', $rawKey); $stmt = $pdo->prepare(" INSERT INTO licenses (license_key_hash, domain, expires_at) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE license_key_hash = VALUES(license_key_hash), expires_at = VALUES(expires_at), status = 'active' "); $stmt->execute([$keyHash, $domain, $expires]); echo "License added/updated."; 3.2 Set Site Message // admin_message.php if ($_POST['set_message']) $msg = $_POST['message_text']; $type = $_POST['message_type']; // Deactivate all old messages $pdo->exec("UPDATE site_messages SET is_active = 0"); $stmt = $pdo->prepare(" INSERT INTO site_messages (message_text, message_type, is_active) VALUES (?, ?, 1) "); $stmt->execute([$msg, $type]); echo "Site message updated.";
This is designed as a (PHP/MySQL) with a simple frontend UI (HTML/JS) — but the logic can be adapted to Node.js, Python, etc.
if ($action === 'verify_license') $rawKey = $_POST['license_key'] ?? ''; $domain = $_POST['domain'] ?? $_SERVER['HTTP_HOST']; echo json_encode($manager->validateLicense($rawKey, $domain)); "License is $license['status']"]
if ($license['status'] !== 'active') return ['valid' => false, 'reason' => "License is $license['status']"];
if (!$license) return ['valid' => false, 'reason' => 'Invalid license key or domain'];
// Get active site message public function getActiveMessage() $stmt = $this->pdo->prepare(" SELECT message_text, message_type FROM site_messages WHERE is_active = 1 LIMIT 1 "); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC) ?: null;
$now = new DateTime(); $expires = new DateTime($license['expires_at']); if ($now > $expires) return ['valid' => false, 'reason' => 'License expired'];
const res = await fetch('/license_api.php?action=verify_license', method: 'POST', body: formData ); const data = await res.json(); const statusDiv = document.getElementById('license-status'); if (data.valid) statusDiv.innerHTML = `<span style="color:green">✅ License valid until $data.expires_at</span>`; loadSiteMessage(); else statusDiv.innerHTML = `<span style="color:red">❌ License invalid: $data.reason</span>`; // Optional: block site content document.body.innerHTML = '<h1>Access Denied</h1><p>Invalid license.</p>';