passphrase generator on CLI
This commit is contained in:
parent
0361cd1982
commit
bd381073b0
2
jslib
2
jslib
|
@ -1 +1 @@
|
||||||
Subproject commit c3f67dbe26d7d5b30645a2857fd9f316fce7b6bc
|
Subproject commit a867c14b2a8bb5f75cd495018e6c86eff22651b9
|
|
@ -15,6 +15,9 @@ export class GenerateCommand {
|
||||||
number: cmd.number || false,
|
number: cmd.number || false,
|
||||||
special: cmd.special || false,
|
special: cmd.special || false,
|
||||||
length: cmd.length || 14,
|
length: cmd.length || 14,
|
||||||
|
type: cmd.passphrase ? 'passphrase' : 'password',
|
||||||
|
wordSeparator: cmd.separator == null ? '-' : cmd.separator,
|
||||||
|
numWords: cmd.words || 3,
|
||||||
};
|
};
|
||||||
if (!options.uppercase && !options.lowercase && !options.special && !options.number) {
|
if (!options.uppercase && !options.lowercase && !options.special && !options.number) {
|
||||||
options.lowercase = true;
|
options.lowercase = true;
|
||||||
|
@ -24,6 +27,14 @@ export class GenerateCommand {
|
||||||
if (options.length < 5) {
|
if (options.length < 5) {
|
||||||
options.length = 5;
|
options.length = 5;
|
||||||
}
|
}
|
||||||
|
if (options.numWords < 3) {
|
||||||
|
options.numWords = 3;
|
||||||
|
}
|
||||||
|
if (options.wordSeparator === 'space') {
|
||||||
|
options.wordSeparator = ' ';
|
||||||
|
} else if (options.wordSeparator != null && options.wordSeparator.length > 1) {
|
||||||
|
options.wordSeparator = options.wordSeparator[0];
|
||||||
|
}
|
||||||
const password = await this.passwordGenerationService.generatePassword(options);
|
const password = await this.passwordGenerationService.generatePassword(options);
|
||||||
const res = new StringResponse(password);
|
const res = new StringResponse(password);
|
||||||
return Response.success(res);
|
return Response.success(res);
|
||||||
|
|
|
@ -409,12 +409,15 @@ export class Program {
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('generate')
|
.command('generate')
|
||||||
.description('Generate a password.')
|
.description('Generate a password/passphrase.')
|
||||||
.option('-u, --uppercase', 'Include uppercase characters.')
|
.option('-u, --uppercase', 'Include uppercase characters.')
|
||||||
.option('-l, --lowercase', 'Include lowercase characters.')
|
.option('-l, --lowercase', 'Include lowercase characters.')
|
||||||
.option('-n, --number', 'Include numeric characters.')
|
.option('-n, --number', 'Include numeric characters.')
|
||||||
.option('-s, --special', 'Include special characters.')
|
.option('-s, --special', 'Include special characters.')
|
||||||
|
.option('-p, --passphrase', 'Generate a passphrase.')
|
||||||
.option('--length <length>', 'Length of the password.')
|
.option('--length <length>', 'Length of the password.')
|
||||||
|
.option('--words <words>', 'Number of words.')
|
||||||
|
.option('--separator <separator>', 'Word separator.')
|
||||||
.on('--help', () => {
|
.on('--help', () => {
|
||||||
writeLn('\n Notes:');
|
writeLn('\n Notes:');
|
||||||
writeLn('');
|
writeLn('');
|
||||||
|
@ -422,12 +425,16 @@ export class Program {
|
||||||
writeLn('');
|
writeLn('');
|
||||||
writeLn(' Minimum `length` is 5.');
|
writeLn(' Minimum `length` is 5.');
|
||||||
writeLn('');
|
writeLn('');
|
||||||
|
writeLn(' Minimum `words` is 3.');
|
||||||
|
writeLn('');
|
||||||
writeLn(' Examples:');
|
writeLn(' Examples:');
|
||||||
writeLn('');
|
writeLn('');
|
||||||
writeLn(' bw generate');
|
writeLn(' bw generate');
|
||||||
writeLn(' bw generate -u -l --length 18');
|
writeLn(' bw generate -u -l --length 18');
|
||||||
writeLn(' bw generate -ulns --length 25');
|
writeLn(' bw generate -ulns --length 25');
|
||||||
writeLn(' bw generate -ul');
|
writeLn(' bw generate -ul');
|
||||||
|
writeLn(' bw generate -p --separator _');
|
||||||
|
writeLn(' bw generate -p --words 5 --separator space');
|
||||||
writeLn('', true);
|
writeLn('', true);
|
||||||
})
|
})
|
||||||
.action(async (cmd) => {
|
.action(async (cmd) => {
|
||||||
|
|
Loading…
Reference in New Issue