passphrase cleanup
This commit is contained in:
parent
c4da05dbb0
commit
d5f86747bf
|
@ -2,6 +2,7 @@ import { GeneratedPasswordHistory } from '../models/domain/generatedPasswordHist
|
||||||
|
|
||||||
export abstract class PasswordGenerationService {
|
export abstract class PasswordGenerationService {
|
||||||
generatePassword: (options: any) => Promise<string>;
|
generatePassword: (options: any) => Promise<string>;
|
||||||
|
generatePassphrase: (options: any) => Promise<string>;
|
||||||
getOptions: () => any;
|
getOptions: () => any;
|
||||||
saveOptions: (options: any) => Promise<any>;
|
saveOptions: (options: any) => Promise<any>;
|
||||||
getHistory: () => Promise<GeneratedPasswordHistory[]>;
|
getHistory: () => Promise<GeneratedPasswordHistory[]>;
|
||||||
|
|
|
@ -17,6 +17,7 @@ export class PasswordGeneratorComponent implements OnInit {
|
||||||
password: string = '-';
|
password: string = '-';
|
||||||
showOptions = false;
|
showOptions = false;
|
||||||
avoidAmbiguous = false;
|
avoidAmbiguous = false;
|
||||||
|
type = '0';
|
||||||
|
|
||||||
constructor(protected passwordGenerationService: PasswordGenerationService,
|
constructor(protected passwordGenerationService: PasswordGenerationService,
|
||||||
protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService,
|
protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService,
|
||||||
|
@ -25,6 +26,7 @@ export class PasswordGeneratorComponent implements OnInit {
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.options = await this.passwordGenerationService.getOptions();
|
this.options = await this.passwordGenerationService.getOptions();
|
||||||
this.avoidAmbiguous = !this.options.ambiguous;
|
this.avoidAmbiguous = !this.options.ambiguous;
|
||||||
|
this.type = this.options.type === 1 ? '1' : '0';
|
||||||
this.password = await this.passwordGenerationService.generatePassword(this.options);
|
this.password = await this.passwordGenerationService.generatePassword(this.options);
|
||||||
this.platformUtilsService.eventTrack('Generated Password');
|
this.platformUtilsService.eventTrack('Generated Password');
|
||||||
await this.passwordGenerationService.addHistory(this.password);
|
await this.passwordGenerationService.addHistory(this.password);
|
||||||
|
@ -77,12 +79,7 @@ export class PasswordGeneratorComponent implements OnInit {
|
||||||
this.options.minLowercase = 0;
|
this.options.minLowercase = 0;
|
||||||
this.options.minUppercase = 0;
|
this.options.minUppercase = 0;
|
||||||
this.options.ambiguous = !this.avoidAmbiguous;
|
this.options.ambiguous = !this.avoidAmbiguous;
|
||||||
|
this.options.type = this.type == null || this.type === '0' ? 0 : 1;
|
||||||
let typePassword = false;
|
|
||||||
if (!this.options.generateTypePassword || this.options.generateTypePassword === 'generate-password') {
|
|
||||||
typePassword = true;
|
|
||||||
}
|
|
||||||
this.options.generatePassphrase = !typePassword;
|
|
||||||
|
|
||||||
if (!this.options.uppercase && !this.options.lowercase && !this.options.number && !this.options.special) {
|
if (!this.options.uppercase && !this.options.lowercase && !this.options.number && !this.options.special) {
|
||||||
this.options.lowercase = true;
|
this.options.lowercase = true;
|
||||||
|
@ -118,8 +115,10 @@ export class PasswordGeneratorComponent implements OnInit {
|
||||||
this.options.minSpecial = this.options.length - this.options.minNumber;
|
this.options.minSpecial = this.options.length - this.options.minNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.options.numWords || this.options.length < 3) {
|
if (this.options.numWords == null || this.options.length < 3) {
|
||||||
this.options.numWords = 3;
|
this.options.numWords = 3;
|
||||||
|
} else if (this.options.numWords > 20) {
|
||||||
|
this.options.numWords = 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
15554
src/misc/wordlist.ts
15554
src/misc/wordlist.ts
File diff suppressed because it is too large
Load Diff
|
@ -40,8 +40,8 @@ import { OnePassword1PifImporter } from '../importers/onepassword1PifImporter';
|
||||||
import { OnePasswordWinCsvImporter } from '../importers/onepasswordWinCsvImporter';
|
import { OnePasswordWinCsvImporter } from '../importers/onepasswordWinCsvImporter';
|
||||||
import { PadlockCsvImporter } from '../importers/padlockCsvImporter';
|
import { PadlockCsvImporter } from '../importers/padlockCsvImporter';
|
||||||
import { PassKeepCsvImporter } from '../importers/passkeepCsvImporter';
|
import { PassKeepCsvImporter } from '../importers/passkeepCsvImporter';
|
||||||
import { PasspackCsvImporter } from '../importers/passpackCsvImporter';
|
|
||||||
import { PassmanJsonImporter } from '../importers/passmanJsonImporter';
|
import { PassmanJsonImporter } from '../importers/passmanJsonImporter';
|
||||||
|
import { PasspackCsvImporter } from '../importers/passpackCsvImporter';
|
||||||
import { PasswordAgentCsvImporter } from '../importers/passwordAgentCsvImporter';
|
import { PasswordAgentCsvImporter } from '../importers/passwordAgentCsvImporter';
|
||||||
import { PasswordBossJsonImporter } from '../importers/passwordBossJsonImporter';
|
import { PasswordBossJsonImporter } from '../importers/passwordBossJsonImporter';
|
||||||
import { PasswordDragonXmlImporter } from '../importers/passwordDragonXmlImporter';
|
import { PasswordDragonXmlImporter } from '../importers/passwordDragonXmlImporter';
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
} from '../abstractions/passwordGeneration.service';
|
} from '../abstractions/passwordGeneration.service';
|
||||||
import { StorageService } from '../abstractions/storage.service';
|
import { StorageService } from '../abstractions/storage.service';
|
||||||
|
|
||||||
import { WordList } from '../misc/wordlist';
|
import { EEFLongWordList } from '../misc/wordlist';
|
||||||
|
|
||||||
const DefaultOptions = {
|
const DefaultOptions = {
|
||||||
length: 14,
|
length: 14,
|
||||||
|
@ -20,6 +20,9 @@ const DefaultOptions = {
|
||||||
minLowercase: 0,
|
minLowercase: 0,
|
||||||
special: false,
|
special: false,
|
||||||
minSpecial: 1,
|
minSpecial: 1,
|
||||||
|
type: 0,
|
||||||
|
numWords: 3,
|
||||||
|
wordSeparator: ' ',
|
||||||
};
|
};
|
||||||
|
|
||||||
const Keys = {
|
const Keys = {
|
||||||
|
@ -39,7 +42,7 @@ export class PasswordGenerationService implements PasswordGenerationServiceAbstr
|
||||||
// overload defaults with given options
|
// overload defaults with given options
|
||||||
const o = Object.assign({}, DefaultOptions, options);
|
const o = Object.assign({}, DefaultOptions, options);
|
||||||
|
|
||||||
if (o.generatePassphrase) {
|
if (o.type === 1) { // TODO: enum?
|
||||||
return this.generatePassphrase(options);
|
return this.generatePassphrase(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,13 +162,20 @@ export class PasswordGenerationService implements PasswordGenerationServiceAbstr
|
||||||
async generatePassphrase(options: any): Promise<string> {
|
async generatePassphrase(options: any): Promise<string> {
|
||||||
const o = Object.assign({}, DefaultOptions, options);
|
const o = Object.assign({}, DefaultOptions, options);
|
||||||
|
|
||||||
const listLength = WordList.length - 1;
|
if (o.numWords == null || o.numWords <= 2) {
|
||||||
|
o.numWords = DefaultOptions.numWords;
|
||||||
|
}
|
||||||
|
if (o.wordSeparator == null || o.wordSeparator.length === 0 || o.wordSeparator.length > 1) {
|
||||||
|
o.wordSeparator = DefaultOptions.wordSeparator;
|
||||||
|
}
|
||||||
|
|
||||||
|
const listLength = EEFLongWordList.length - 1;
|
||||||
const wordList = new Array(o.numWords);
|
const wordList = new Array(o.numWords);
|
||||||
for (let i = 0; i < o.numWords; i++) {
|
for (let i = 0; i < o.numWords; i++) {
|
||||||
const wordindex = await this.cryptoService.randomNumber(0, listLength);
|
const wordIndex = await this.cryptoService.randomNumber(0, listLength);
|
||||||
wordList[i] = WordList[wordindex];
|
wordList[i] = EEFLongWordList[wordIndex];
|
||||||
}
|
}
|
||||||
return wordList.join(' ');
|
return wordList.join(o.wordSeparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOptions() {
|
async getOptions() {
|
||||||
|
|
Loading…
Reference in New Issue