mirror of
https://gitgud.io/fatchan/haproxy-protection.git
synced 2025-05-09 02:05:37 +00:00
Allow a bit better granularity for the difficulty. Recommend an "easier" challenge in terms of memory and iterations, but higher diff.
Make failed request for captcha/bot form show a little error text. Make CHALLENGE_INCLUDES_IP "1" = on, anything else = off instead of needing to be unset.
This commit is contained in:
@ -19,7 +19,9 @@ function postResponse(powResponse, captchaResponse) {
|
||||
redirect: 'manual',
|
||||
}).then(res => {
|
||||
finishRedirect();
|
||||
})
|
||||
}).catch(err => {
|
||||
document.querySelector('.lds-ring').insertAdjacentHTML('afterend', '<p class="red">An error occurred.</p>');
|
||||
});
|
||||
}
|
||||
|
||||
const powFinished = new Promise((resolve, reject) => {
|
||||
@ -33,7 +35,7 @@ const powFinished = new Promise((resolve, reject) => {
|
||||
type: argon2.ArgonType.Argon2id,
|
||||
};
|
||||
console.log('Got pow', pow, 'with difficulty', diff);
|
||||
const diffString = '0'.repeat(diff);
|
||||
const diffString = '0'.repeat(Math.floor(diff/8));
|
||||
const combined = pow;
|
||||
const [userkey, challenge, signature] = combined.split("#");
|
||||
const start = Date.now();
|
||||
@ -59,7 +61,7 @@ const powFinished = new Promise((resolve, reject) => {
|
||||
}
|
||||
for (let i = 0; i < threads; i++) {
|
||||
await new Promise(res => setTimeout(res, 100));
|
||||
workers[i].postMessage([userkey, challenge, diffString, argonOpts, i, threads]);
|
||||
workers[i].postMessage([userkey, challenge, diff, diffString, argonOpts, i, threads]);
|
||||
}
|
||||
} else {
|
||||
console.warn('No webworker support, running in main/UI thread!');
|
||||
@ -71,7 +73,9 @@ const powFinished = new Promise((resolve, reject) => {
|
||||
salt: userkey,
|
||||
...argonOpts,
|
||||
});
|
||||
if (hash.hashHex.startsWith(diffString)) {
|
||||
if (hash.hashHex.startsWith(diffString)
|
||||
&& ((parseInt(hash.hashHex[diffString.length],16) &
|
||||
0xff >> (((diffString.length+1)*8)-diff)) === 0)) {
|
||||
console.log('Main thread found solution:', hash.hashHex, 'in', (Date.now()-start)+'ms');
|
||||
break;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
importScripts('/js/argon2.js');
|
||||
|
||||
onmessage = async function(e) {
|
||||
const [userkey, challenge, diffString, argonOpts, id, threads] = e.data;
|
||||
const [userkey, challenge, diff, diffString, argonOpts, id, threads] = e.data;
|
||||
console.log('Worker thread', id, 'started');
|
||||
let i = id;
|
||||
while(true) {
|
||||
@ -12,7 +12,9 @@ onmessage = async function(e) {
|
||||
});
|
||||
// This throttle seems to really help some browsers not stop the workers abruptly
|
||||
i % 10 === 0 && await new Promise(res => setTimeout(res, 10));
|
||||
if (hash.hashHex.startsWith(diffString)) {
|
||||
if (hash.hashHex.startsWith(diffString)
|
||||
&& ((parseInt(hash.hashHex[diffString.length],16) &
|
||||
0xff >> (((diffString.length+1)*8)-diff)) === 0)) {
|
||||
console.log('Worker', id, 'found solution');
|
||||
postMessage([id, i]);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user