From bd381073b04649efe412b12cb69aead149743fba Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 8 Oct 2018 22:57:36 -0400 Subject: [PATCH] passphrase generator on CLI --- jslib | 2 +- src/commands/generate.command.ts | 11 +++++++++++ src/program.ts | 9 ++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/jslib b/jslib index c3f67dbe26..a867c14b2a 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit c3f67dbe26d7d5b30645a2857fd9f316fce7b6bc +Subproject commit a867c14b2a8bb5f75cd495018e6c86eff22651b9 diff --git a/src/commands/generate.command.ts b/src/commands/generate.command.ts index 97a7fc1baf..cda624130c 100644 --- a/src/commands/generate.command.ts +++ b/src/commands/generate.command.ts @@ -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); diff --git a/src/program.ts b/src/program.ts index b0a388c8e8..f57f5e3378 100644 --- a/src/program.ts +++ b/src/program.ts @@ -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 of the password.') + .option('--words ', 'Number of words.') + .option('--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) => {