-
Notifications
You must be signed in to change notification settings - Fork 499
/
Copy pathpasswordStrengthChecker.js
87 lines (78 loc) · 2.72 KB
/
passwordStrengthChecker.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const fs = require("fs");
const path = require("path");
let Turbit;
try {
// Try to import the installed version of Turbit
Turbit = require("turbit");
} catch (error) {
// If the library is not installed, use the local version
Turbit = require("../../turbit");
}
// Create a Turbit instance for parallel processing
const turbit = Turbit();
/**
* passwordGenerator: Generates a strong password of a predefined length using a set of characters.
*/
const passwordGenerator = function() {
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}|;':\",.<>/?";
const length = 22;
let password = "";
for (let i = 0; i < length; i++) {
const random = Math.floor(Math.random() * chars.length);
password += chars[random];
}
return password;
}
/**
* checkStrength: Checks the strength of an array of passwords based on specific criteria.
*/
const checkStrength = function(passwords) {
return passwords.map(password => {
const uppercase = /[A-Z]/.test(password);
const lowercase = /[a-z]/.test(password);
const numbers = /\d/.test(password);
const special = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/.test(password);
const isStrong = password.length >= 8 && uppercase && lowercase && numbers && special;
return { password, isStrong };
});
}
/**
* saveDataPasswords: Saves the password strength check results to a CSV file.
*/
const saveDataPasswords = function(results, filename) {
const csvLines = results.map(result =>
`"${result.password.replace(/"/g, '""')}",${result.isStrong}`
);
csvLines.unshift("password,isStrong");
fs.writeFileSync(filename, csvLines.join("\n"));
}
/**
* main: Generate passwords, check their strength, and save the results.
*/
const main = async function() {
const numPasswords = 1000000; // At this moment it generates a million data, but you can modify it to your liking.
const passwords = Array.from({ length: numPasswords }, passwordGenerator);
try {
const results = await turbit.run(checkStrength, {
type: "extended",
data: passwords,
power: 100 // Uses 100% of available cores
});
turbit.kill();
saveDataPasswords(results.data, path.join(__dirname, "passwords.csv"));
console.log("")
console.log("")
console.log("Generated passwords:", numPasswords)
console.log("-")
console.log('Results saved in passwords.csv');
console.log("-")
console.log("Stats:", results.stats)
console.log("")
console.log("")
} catch (error) {
console.error(`Error: ${error.message}`);
} finally {
turbit.kill();
}
}
main();