-
Notifications
You must be signed in to change notification settings - Fork 0
/
pass.js
54 lines (45 loc) · 1.36 KB
/
pass.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
const argv = process.argv
let sources = {
'l': "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
'd': "0123456789",
"c": "абвшдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ",
"s": "`~!@#$%^&*()_+-='\\\"|/.?,",
}
const sourcesKeys = Object.keys(sources)
let length = 20
let charset = ""
let template = ""
let lengthAccessed = false
for (let arg of argv) {
let dashIndex = arg.indexOf('-');
if (dashIndex == 0 || dashIndex == 1) {
let flagChars = arg.slice(dashIndex + 1, arg.length)?.toLowerCase().split('')
let badFlag = false
for (let char of flagChars) {
if (sourcesKeys.indexOf(char) == -1) {
badFlag = true
break
}
}
if (!badFlag) {
flagChars.forEach(c => template += c)
}
} else if (!lengthAccessed) {
const value = parseInt(arg)
if (!isNaN(value)) {
length = value
lengthAccessed = true
}
}
}
if (!template.length) {
template = 'ld'
}
for (let k of template) {
charset += sources[k]
}
var retVal = ""
for (var i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n))
}
console.log(retVal)