1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-05 09:10:53 +01:00

Add a passphrase generation mechanism (#12)

Based on EFF's wordlist
The wordlist was selected based on arguments mentionned in
https://www.eff.org/deeplinks/2016/07/new-wordlists-random-passphrases
over Arnold Reinhold's Diceware list from 1995 such as avoid short,
deused or diffcult to pronounce words
This commit is contained in:
Martin Trigaux 2018-10-08 23:26:13 +02:00 committed by Kyle Spearrin
parent 7b3fce1779
commit c4da05dbb0
3 changed files with 7805 additions and 0 deletions

View File

@ -78,6 +78,12 @@ export class PasswordGeneratorComponent implements OnInit {
this.options.minUppercase = 0;
this.options.ambiguous = !this.avoidAmbiguous;
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) {
this.options.lowercase = true;
const lowercase = document.querySelector('#lowercase') as HTMLInputElement;
@ -111,5 +117,9 @@ export class PasswordGeneratorComponent implements OnInit {
if (this.options.minSpecial + this.options.minNumber > this.options.length) {
this.options.minSpecial = this.options.length - this.options.minNumber;
}
if (!this.options.numWords || this.options.length < 3) {
this.options.numWords = 3;
}
}
}

7777
src/misc/wordlist.ts Normal file

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,8 @@ import {
} from '../abstractions/passwordGeneration.service';
import { StorageService } from '../abstractions/storage.service';
import { WordList } from '../misc/wordlist';
const DefaultOptions = {
length: 14,
ambiguous: false,
@ -37,6 +39,10 @@ export class PasswordGenerationService implements PasswordGenerationServiceAbstr
// overload defaults with given options
const o = Object.assign({}, DefaultOptions, options);
if (o.generatePassphrase) {
return this.generatePassphrase(options);
}
// sanitize
if (o.uppercase && o.minUppercase <= 0) {
o.minUppercase = 1;
@ -150,6 +156,18 @@ export class PasswordGenerationService implements PasswordGenerationServiceAbstr
return password;
}
async generatePassphrase(options: any): Promise<string> {
const o = Object.assign({}, DefaultOptions, options);
const listLength = WordList.length - 1;
const wordList = new Array(o.numWords);
for (let i = 0; i < o.numWords; i++) {
const wordindex = await this.cryptoService.randomNumber(0, listLength);
wordList[i] = WordList[wordindex];
}
return wordList.join(' ');
}
async getOptions() {
if (this.optionsCache == null) {
const options = await this.storageService.get(Keys.options);