PHP code example of horsev / expiring-key-generator
1. Go to this page and download the library: Download horsev/expiring-key-generator library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
horsev / expiring-key-generator example snippets
use Horsev\ExpiringKeyGenerator\ExpiringKeyGenerator;
// 1. Generate a secret key (store this securely)
$secretKey = ExpiringKeyGenerator::generateSecretKey();
// 2. Daily keys — generate and validate within N days
$generateKey = ExpiringKeyGenerator::createKeyGenerator($secretKey);
$key = $generateKey(new DateTime());
$isKeyValid = ExpiringKeyGenerator::createKeyValidator($secretKey);
$isKeyValid($key, new DateTime(), 28); // true
// 3. Hourly keys — generate and validate within N hours (1–24)
$generateHourlyKey = ExpiringKeyGenerator::createHourlyKeyGenerator($secretKey);
$hourlyKey = $generateHourlyKey(new DateTime());
$isHourlyKeyValid = ExpiringKeyGenerator::createHourlyKeyValidator($secretKey);
$isHourlyKeyValid($hourlyKey, new DateTime(), 5); // true