1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

password strength function with zxcvbn

This commit is contained in:
Kyle Spearrin
2018-11-12 22:54:18 -05:00
parent 786fa02b90
commit aa16fb2a9e
5 changed files with 56 additions and 2 deletions

View File

@@ -1,3 +1,5 @@
import * as zxcvbn from 'zxcvbn';
import { CipherString } from '../models/domain/cipherString';
import { GeneratedPasswordHistory } from '../models/domain/generatedPasswordHistory';
@@ -240,6 +242,20 @@ export class PasswordGenerationService implements PasswordGenerationServiceAbstr
return await this.storageService.remove(Keys.history);
}
passwordStrength(password: string, userInputs: string[] = null): zxcvbn.ZXCVBNResult {
if (password == null || password.length === 0) {
return null;
}
let globalUserInputs = ['bitwarden', 'bit', 'warden'];
if (userInputs != null) {
globalUserInputs = globalUserInputs.concat(userInputs);
}
// Use a hash set to get rid of any duplicate user inputs
const finalUserInputs = Array.from(new Set(globalUserInputs));
const result = zxcvbn(password, finalUserInputs);
return result;
}
private async encryptHistory(history: GeneratedPasswordHistory[]): Promise<GeneratedPasswordHistory[]> {
if (history == null || history.length === 0) {
return Promise.resolve([]);