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

Password Generator Sanitize Length (#89)

* Initial commit for length sanitization

* Updated sanitize function

* Updated type instantiation

Co-authored-by: Vincent Salucci <vsalucci@bitwarden.com>
This commit is contained in:
Vincent Salucci
2020-03-18 10:07:57 -05:00
committed by GitHub
parent 0a30c7eb1e
commit 3ad546c39f
3 changed files with 113 additions and 80 deletions

View File

@@ -80,8 +80,7 @@ export class PasswordGeneratorComponent implements OnInit {
}
private normalizeOptions() {
this.options.minLowercase = 0;
this.options.minUppercase = 0;
// Application level normalize options depedent on class variables
this.options.ambiguous = !this.avoidAmbiguous;
if (!this.options.uppercase && !this.options.lowercase && !this.options.number && !this.options.special) {
@@ -94,56 +93,6 @@ export class PasswordGeneratorComponent implements OnInit {
}
}
if (!this.options.length || this.options.length < 5) {
this.options.length = 5;
} else if (this.options.length > 128) {
this.options.length = 128;
}
if (this.options.length < this.enforcedPolicyOptions.minLength) {
this.options.length = this.enforcedPolicyOptions.minLength;
}
if (!this.options.minNumber) {
this.options.minNumber = 0;
} else if (this.options.minNumber > this.options.length) {
this.options.minNumber = this.options.length;
} else if (this.options.minNumber > 9) {
this.options.minNumber = 9;
}
if (this.options.minNumber < this.enforcedPolicyOptions.numberCount) {
this.options.minNumber = this.enforcedPolicyOptions.numberCount;
}
if (!this.options.minSpecial) {
this.options.minSpecial = 0;
} else if (this.options.minSpecial > this.options.length) {
this.options.minSpecial = this.options.length;
} else if (this.options.minSpecial > 9) {
this.options.minSpecial = 9;
}
if (this.options.minSpecial < this.enforcedPolicyOptions.specialCount) {
this.options.minSpecial = this.enforcedPolicyOptions.specialCount;
}
if (this.options.minSpecial + this.options.minNumber > this.options.length) {
this.options.minSpecial = this.options.length - this.options.minNumber;
}
if (this.options.numWords == null || this.options.length < 3) {
this.options.numWords = 3;
} else if (this.options.numWords > 20) {
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];
}
this.passwordGenerationService.normalizeOptions(this.options, this.enforcedPolicyOptions);
}
}