-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·98 lines (94 loc) · 2.6 KB
/
Copy pathcli.js
File metadata and controls
executable file
·98 lines (94 loc) · 2.6 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
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
90
91
92
93
94
95
96
97
98
#!/usr/bin/env node
var argparse = require('argparse');
var pack = require('./package.json');
var generate = require('./');
var chalk = require('chalk');
var parser = new argparse.ArgumentParser({
description: pack.description,
version: pack.version
});
parser.addArgument(['-d', '--dictionary'], {
help: '`xkcd` (2k, most memorable), `letterpress` (270k) or `mixed`.',
type: 'string',
defaultValue: 'mixed'
});
parser.addArgument(['-w', '--word-num'], {
help: 'Number of words to generate.',
type: 'int',
defaultValue: 4
});
parser.addArgument(['--word-min'], {
help: 'Minimum length of each word.',
type: 'int',
defaultValue: 4
});
parser.addArgument(['--word-max'], {
help: 'Maximum length of each word.',
type: 'int',
defaultValue: 8
});
parser.addArgument(['-s', '--separator'], {
help: 'How to join words.',
type: 'string',
defaultValue: '-'
});
parser.addArgument(['--pad-digit-before'], {
help: 'How many digits to add before the pass.',
type: 'int',
defaultValue: 0
});
parser.addArgument(['--pad-digit-after'], {
help: 'How many digits to add after the pass.',
type: 'int',
defaultValue: 1
});
parser.addArgument(['--pad-symbols'], {
help: 'Which symbols to use in padding.',
type: 'string',
defaultValue: '!@#$%^&*()'
});
parser.addArgument(['--pad-symbol-before'], {
help: 'How many symbols to add before the pass.',
type: 'int',
defaultValue: 0
});
parser.addArgument(['--pad-symbol-after'], {
help: 'How many symbols to add after the pass.',
type: 'int',
defaultValue: 1
});
var args = parser.parseArgs();
var pass = generate({
words: {
dictionary: args.dictionary,
num: args.word_num,
min: args.word_min,
max: args.word_max
},
separator: args.separator,
paddingDigits: {
before: args.pad_digit_before,
after: args.pad_digit_after
},
paddingSymbols: {
symbols: args.pad_symbols,
before: args.pad_symbol_before,
after: args.pad_symbol_after
}
});
var ratingColour = '';
switch (pass.rating.rate) {
case 'very weak': ratingColour = 'red'; break;
case 'weak': ratingColour = 'magenta'; break;
case 'reasonable': ratingColour = 'yellow'; break;
case 'strong': ratingColour = 'blue'; break;
case 'very strong': ratingColour = 'green'; break;
default: ratingColour = 'gray'; break;
}
console.log(pack.description);
console.log('Generated password: [ ' + chalk.gray(pass.pass) + ' ] ');
console.log('Entropy: ' + chalk.bold(pass.entropy));
console.log('Blind entropy: ' + chalk.bold(pass.blindEntropy));
console.log('Rating: ' +
chalk[ratingColour].bold(pass.rating.rate) + ': ' +
chalk[ratingColour](pass.rating.comment));