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:
@@ -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([]);
|
||||
|
||||
Reference in New Issue
Block a user