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:
Thomas Lynch
2022-10-01 05:31:47 +10:00
parent 434756a7a1
commit eede92d47d
5 changed files with 35 additions and 14 deletions

View File

@ -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;