35 lines
1.0 KiB
PHP
35 lines
1.0 KiB
PHP
<?php
|
|
require_once '/var/www/html/elements/lib/altcha/autoload.php';
|
|
|
|
use AltchaOrg\Altcha\Algorithm\Pbkdf2;
|
|
use AltchaOrg\Altcha\Altcha;
|
|
use AltchaOrg\Altcha\CreateChallengeOptions;
|
|
|
|
$secret = hash_hmac('sha256', 'lettersail-captcha', (string) $modx->getOption('site_id', null, 'lettersail'));
|
|
$challenge = (new Altcha(hmacSignatureSecret: $secret))->createChallenge(
|
|
new CreateChallengeOptions(
|
|
algorithm: new Pbkdf2(),
|
|
cost: 2000,
|
|
counter: random_int(1000, 2000),
|
|
expiresAt: time() + 1200,
|
|
)
|
|
)->toArray();
|
|
|
|
$stamp = (string) (int) (microtime(true) * 1000);
|
|
setcookie('ls_t', $stamp . '.' . hash_hmac('sha256', $stamp, $secret), [
|
|
'expires' => time() + 86400,
|
|
'path' => '/',
|
|
'secure' => true,
|
|
'httponly' => true,
|
|
'samesite' => 'Lax',
|
|
]);
|
|
|
|
while (ob_get_level()) {
|
|
ob_end_clean();
|
|
}
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
header('Cache-Control: no-store');
|
|
header('X-Robots-Tag: noindex');
|
|
echo json_encode($challenge, JSON_UNESCAPED_UNICODE);
|
|
exit;
|