1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00: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

@@ -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);