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

@@ -262,6 +262,24 @@ export class PasswordGenerationService implements PasswordGenerationServiceAbstr
if (options.minSpecial + options.minNumber > options.length) {
options.minSpecial = options.length - options.minNumber;
}
if (options.numWords < enforcedPolicyOptions.minNumberWords) {
options.numWords = enforcedPolicyOptions.minNumberWords;
}
if (enforcedPolicyOptions.capitalize) {
options.capitalize = true;
}
if (enforcedPolicyOptions.includeNumber) {
options.includeNumber = true;
}
// Force default type if password/passphrase selected via policy
if (enforcedPolicyOptions.defaultType === 'password' ||
enforcedPolicyOptions.defaultType === 'passphrase') {
options.type = enforcedPolicyOptions.defaultType;
}
} else { // UI layer expects an instantiated object to prevent more explicit null checks
enforcedPolicyOptions = new PasswordGeneratorPolicyOptions();
}
@@ -285,6 +303,11 @@ export class PasswordGenerationService implements PasswordGenerationServiceAbstr
enforcedOptions = new PasswordGeneratorPolicyOptions();
}
// Password wins in multi-org collisions
if (currentPolicy.data.defaultType != null && enforcedOptions.defaultType !== 'password') {
enforcedOptions.defaultType = currentPolicy.data.defaultType;
}
if (currentPolicy.data.minLength != null
&& currentPolicy.data.minLength > enforcedOptions.minLength) {
enforcedOptions.minLength = currentPolicy.data.minLength;
@@ -315,6 +338,19 @@ export class PasswordGenerationService implements PasswordGenerationServiceAbstr
&& currentPolicy.data.minSpecial > enforcedOptions.specialCount) {
enforcedOptions.specialCount = currentPolicy.data.minSpecial;
}
if (currentPolicy.data.minNumberWords != null
&& currentPolicy.data.minNumberWords > enforcedOptions.minNumberWords) {
enforcedOptions.minNumberWords = currentPolicy.data.minNumberWords;
}
if (currentPolicy.data.capitalize) {
enforcedOptions.capitalize = true;
}
if (currentPolicy.data.includeNumber) {
enforcedOptions.includeNumber = true;
}
});
return enforcedOptions;