-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpasswordgenerator.js
More file actions
50 lines (43 loc) · 1.64 KB
/
passwordgenerator.js
File metadata and controls
50 lines (43 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const readline = require('readline');
const fs = require('fs');
const { Worker, isMainThread, parentPort } = require('worker_threads');
if (isMainThread) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter the number of characters in each combination: ', (answer1) => {
rl.question('Enter the character set to use (default is all characters): ', (answer2) => {
const numChars = parseInt(answer1);
const characters = answer2 || 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-=[]{};:\'",.<>?/\\|';
const file = fs.createWriteStream(`wordlist_char${numChars}.txt`);
const start = process.hrtime();
const worker = new Worker(__filename);
worker.on('message', (msg) => {
file.end();
const end = process.hrtime(start);
console.log(`Generated wordlist_char${numChars}.txt in ${end[0]} seconds and ${end[1]} nanoseconds`);
rl.close();
process.exit();
});
worker.postMessage({ numChars, characters });
});
});
} else {
parentPort.on('message', (msg) =>{
const { numChars, characters } = msg;
async function generateCombinations(combination) {
if (combination.length === numChars) {
fs.appendFileSync(`wordlist_char${numChars}.txt`, combination + '\n');
} else {
for (let i = 0; i < characters.length; i++) {
await generateCombinations(combination + characters[i]);
}
}
}
const generatePromise = generateCombinations('');
generatePromise.then(() => {
parentPort.postMessage(1);
});
})
}