mirror of
https://gitgud.io/fatchan/haproxy-protection.git
synced 2025-05-09 02:05:37 +00:00
- memory and time params customisable as well as "difficulty", default 1 iteration, 6000KB, 3 difficulty. - updated the noscript bash method to work with argon2 - works in webworkers or main thread, capped at 8 threads (doesn't seem to crash firefox anymore -- we could go higher)
23 lines
624 B
JavaScript
23 lines
624 B
JavaScript
importScripts('/js/argon2.js');
|
|
|
|
onmessage = async function(e) {
|
|
const [userkey, challenge, diffString, argonOpts, id, threads] = e.data;
|
|
console.log('Worker thread', id, 'started');
|
|
let i = id;
|
|
while(true) {
|
|
const hash = await argon2.hash({
|
|
pass: challenge + i.toString(),
|
|
salt: userkey,
|
|
...argonOpts,
|
|
});
|
|
// 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)) {
|
|
console.log('Worker', id, 'found solution');
|
|
postMessage([id, i]);
|
|
break;
|
|
}
|
|
i+=threads;
|
|
}
|
|
}
|