-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
89 lines (74 loc) · 2.04 KB
/
index.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
88
89
import alfy from 'alfy';
import { randomInt } from 'crypto';
import lists from './lists.js';
import entropy from './entropy.js';
const os = process.env;
const password = (args) => {
let length = (args) ? args : os.defaultLength;
if (isNaN(length)) {
return output([{
'title': `${length} is not a number`,
'subtitle': '',
'arg': '',
'icon': alfy.icon.error.path
}]);
}
if (length >= 64) {
length = 64;
} else if (length < 1) {
length = 1;
}
let combinations = [
{
title: `${length} characters – letters + digits + symbols`,
dictionary: lists.strings + lists.numbers + lists.punctuation,
delimiter: '',
length: length
},
{
title: `${length} characters – letters + digits`,
dictionary: lists.strings + lists.numbers,
delimiter: '',
length: length
},
{
title: `${length} characters – letters`,
dictionary: lists.strings,
delimiter: '',
length: length
},
{
title: `${os.words} words`,
dictionary: lists.words,
delimiter: '-',
length: os.words
}
];
let items = [];
combinations.forEach(combo => {
items.push(item(combo));
});
output(items);
}
const item = (combo) => {
let parts = [];
for (let index = 0; index < combo.length; index++) {
let number = random(combo.dictionary.length);
parts.push(combo.dictionary[number]);
}
let password = parts.join(combo.delimiter);
let strength = entropy.strength(combo.length, combo.dictionary.length);
let icon = entropy.icon(strength);
return {
'title': combo.title,
'subtitle': `${icon} ${password}`,
'arg': `${password}`,
}
}
const random = (length) => {
return randomInt(1, length);
}
const output = (params) => {
alfy.output(params);
}
password(alfy.input)