1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

Password Generator Passphrase Policy (#85)

* Initial commit for passphrase enforcement

* Updated type implementation

* Updated default type conditional

* Added helper method to enforced options object

Co-authored-by: Vincent Salucci <vsalucci@bitwarden.com>
This commit is contained in:
Vincent Salucci
2020-03-10 12:50:54 -05:00
committed by GitHub
parent 44b86f5dd0
commit ee8ca0beed
3 changed files with 58 additions and 9 deletions

View File

@@ -19,7 +19,6 @@ export class PasswordGeneratorComponent implements OnInit {
password: string = '-';
showOptions = false;
avoidAmbiguous = false;
policyInEffect = false;
enforcedPolicyOptions: PasswordGeneratorPolicyOptions;
constructor(protected passwordGenerationService: PasswordGenerationService,
@@ -30,14 +29,6 @@ export class PasswordGeneratorComponent implements OnInit {
const optionsResponse = await this.passwordGenerationService.getOptions();
this.options = optionsResponse[0];
this.enforcedPolicyOptions = optionsResponse[1];
this.policyInEffect = this.enforcedPolicyOptions != null && (
this.enforcedPolicyOptions.minLength > 0 ||
this.enforcedPolicyOptions.numberCount > 0 ||
this.enforcedPolicyOptions.specialCount > 0 ||
this.enforcedPolicyOptions.useUppercase ||
this.enforcedPolicyOptions.useLowercase ||
this.enforcedPolicyOptions.useNumbers ||
this.enforcedPolicyOptions.useSpecial);
this.avoidAmbiguous = !this.options.ambiguous;
this.options.type = this.options.type === 'passphrase' ? 'passphrase' : 'password';
this.password = await this.passwordGenerationService.generatePassword(this.options);
@@ -147,6 +138,10 @@ export class PasswordGeneratorComponent implements OnInit {
this.options.numWords = 20;
}
if (this.options.numWords < this.enforcedPolicyOptions.minNumberWords) {
this.options.numWords = this.enforcedPolicyOptions.minNumberWords;
}
if (this.options.wordSeparator != null && this.options.wordSeparator.length > 1) {
this.options.wordSeparator = this.options.wordSeparator[0];
}