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,
|
||||
special: cmd.special || false,
|
||||
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) {
|
||||
options.lowercase = true;
|
||||
|
@ -24,6 +27,14 @@ export class GenerateCommand {
|
|||
if (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 res = new StringResponse(password);
|
||||
return Response.success(res);
|
||||
|
|
|
@ -409,12 +409,15 @@ export class Program {
|
|||
|
||||
program
|
||||
.command('generate')
|
||||
.description('Generate a password.')
|
||||
.description('Generate a password/passphrase.')
|
||||
.option('-u, --uppercase', 'Include uppercase characters.')
|
||||
.option('-l, --lowercase', 'Include lowercase characters.')
|
||||
.option('-n, --number', 'Include numeric characters.')
|
||||
.option('-s, --special', 'Include special characters.')
|
||||
.option('-p, --passphrase', 'Generate a passphrase.')
|
||||
.option('--length <length>', 'Length of the password.')
|
||||
.option('--words <words>', 'Number of words.')
|
||||
.option('--separator <separator>', 'Word separator.')
|
||||
.on('--help', () => {
|
||||
writeLn('\n Notes:');
|
||||
writeLn('');
|
||||
|
@ -422,12 +425,16 @@ export class Program {
|
|||
writeLn('');
|
||||
writeLn(' Minimum `length` is 5.');
|
||||
writeLn('');
|
||||
writeLn(' Minimum `words` is 3.');
|
||||
writeLn('');
|
||||
writeLn(' Examples:');
|
||||
writeLn('');
|
||||
writeLn(' bw generate');
|
||||
writeLn(' bw generate -u -l --length 18');
|
||||
writeLn(' bw generate -ulns --length 25');
|
||||
writeLn(' bw generate -ul');
|
||||
writeLn(' bw generate -p --separator _');
|
||||
writeLn(' bw generate -p --words 5 --separator space');
|
||||
writeLn('', true);
|
||||
})
|
||||
.action(async (cmd) => {
|
||||
|
|
Loading…
Reference in New Issue