Subversion Repositories php_clientchallenge

Compare Revisions

Regard whitespace Rev 5 → Rev 6

/trunk/example/ajax_example.php
2,7 → 2,7
 
/*
* php_clientchallenge
* Copyright 2021 Daniel Marschall, ViaThinkSoft
* Copyright 2021-2022 Daniel Marschall, ViaThinkSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
29,7 → 29,9
 
// Check request field "vts_validation_result" for valid response of the Challenge
try {
\ViaThinkSoft\RateLimitingChallenge\ClientChallenge::checkValidation(MAX_TIME, VTS_CS_SERVER_SECRET);
if (!isset($_REQUEST['vts_validation_result'])) throw new \Exception('No challenge response found');
$client_response = @json_decode($_REQUEST['vts_validation_result'], true);
\ViaThinkSoft\RateLimitingChallenge\ClientChallenge::checkValidation($client_response, MAX_TIME, VTS_CS_SERVER_SECRET);
} catch (\Exception $e) {
$res = array("error" => $e->getMessage());
header('Content-Type:application/json');
/trunk/example/ajax_get_challenge.php
2,7 → 2,7
 
/*
* php_clientchallenge
* Copyright 2021 Daniel Marschall, ViaThinkSoft
* Copyright 2021-2022 Daniel Marschall, ViaThinkSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
25,4 → 25,11
 
require_once __DIR__ . '/config.inc.php';
 
\ViaThinkSoft\RateLimitingChallenge\ClientChallenge::createChallenge(COMPLEXITY, VTS_CS_SERVER_SECRET);
try {
$res = \ViaThinkSoft\RateLimitingChallenge\ClientChallenge::createChallenge(COMPLEXITY, VTS_CS_SERVER_SECRET);
} catch (\Exception $e) {
$res = array("error" => $e->getMessage());
}
 
header('Content-Type:application/json');
die(json_encode($res));
/trunk/example/config.inc.php
2,7 → 2,7
 
/*
* php_clientchallenge
* Copyright 2021 Daniel Marschall, ViaThinkSoft
* Copyright 2021-2022 Daniel Marschall, ViaThinkSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
18,5 → 18,5
*/
 
define('VTS_CS_SERVER_SECRET', '1234567890'); // PLEASE CHANGE THIS VALUE TO SOMETHING RANDOM!
define('MAX_TIME', 10); // seconds
define('COMPLEXITY', 500000);
define('MAX_TIME', 15); // seconds
define('COMPLEXITY', 50000);
/trunk/example/index.html
12,6 → 12,7
 
let error_cb = function (request, status, error) {
$("#out").val("Error!");
alert(error);
}
 
let callback = function(params, vts_validation_result) {
29,8 → 30,7
},
success: function(data) {
if ("error" in data) {
$("#out").val('ERROR');
alert(data["error"]);
error_cb(null,null,data["error"]);
} else {
$("#out").val(data["result"]);
}