pass gen fixes. word sep option

This commit is contained in:
Kyle Spearrin 2018-10-08 22:06:06 -04:00
parent d5f86747bf
commit a867c14b2a
2 changed files with 14 additions and 10 deletions

View File

@ -17,7 +17,6 @@ export class PasswordGeneratorComponent implements OnInit {
password: string = '-';
showOptions = false;
avoidAmbiguous = false;
type = '0';
constructor(protected passwordGenerationService: PasswordGenerationService,
protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService,
@ -26,7 +25,7 @@ export class PasswordGeneratorComponent implements OnInit {
async ngOnInit() {
this.options = await this.passwordGenerationService.getOptions();
this.avoidAmbiguous = !this.options.ambiguous;
this.type = this.options.type === 1 ? '1' : '0';
this.options.type = this.options.type === 'passphrase' ? 'passphrase' : 'password';
this.password = await this.passwordGenerationService.generatePassword(this.options);
this.platformUtilsService.eventTrack('Generated Password');
await this.passwordGenerationService.addHistory(this.password);
@ -79,13 +78,14 @@ export class PasswordGeneratorComponent implements OnInit {
this.options.minLowercase = 0;
this.options.minUppercase = 0;
this.options.ambiguous = !this.avoidAmbiguous;
this.options.type = this.type == null || this.type === '0' ? 0 : 1;
if (!this.options.uppercase && !this.options.lowercase && !this.options.number && !this.options.special) {
this.options.lowercase = true;
const lowercase = document.querySelector('#lowercase') as HTMLInputElement;
if (lowercase) {
lowercase.checked = true;
if (this.win != null) {
const lowercase = this.win.document.querySelector('#lowercase') as HTMLInputElement;
if (lowercase) {
lowercase.checked = true;
}
}
}
@ -120,5 +120,9 @@ export class PasswordGeneratorComponent implements OnInit {
} else if (this.options.numWords > 20) {
this.options.numWords = 20;
}
if (this.options.wordSeparator != null && this.options.wordSeparator.length > 1) {
this.options.wordSeparator = this.options.wordSeparator[0];
}
}
}

View File

@ -20,9 +20,9 @@ const DefaultOptions = {
minLowercase: 0,
special: false,
minSpecial: 1,
type: 0,
type: 'password',
numWords: 3,
wordSeparator: ' ',
wordSeparator: '-',
};
const Keys = {
@ -42,7 +42,7 @@ export class PasswordGenerationService implements PasswordGenerationServiceAbstr
// overload defaults with given options
const o = Object.assign({}, DefaultOptions, options);
if (o.type === 1) { // TODO: enum?
if (o.type === 'passphrase') {
return this.generatePassphrase(options);
}
@ -166,7 +166,7 @@ export class PasswordGenerationService implements PasswordGenerationServiceAbstr
o.numWords = DefaultOptions.numWords;
}
if (o.wordSeparator == null || o.wordSeparator.length === 0 || o.wordSeparator.length > 1) {
o.wordSeparator = DefaultOptions.wordSeparator;
o.wordSeparator = ' ';
}
const listLength = EEFLongWordList.length - 1;