1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-18 02:41:15 +02:00

Sort weak passwords by severity (#446)

* Sort weak passwords by weakness

* Move static methods into local const
This commit is contained in:
Naoaki Iwakiri 2021-04-06 07:23:48 +09:00 committed by GitHub
parent 769c247832
commit 89dc3b70e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,7 @@ import { CipherReportComponent } from './cipher-report.component';
templateUrl: 'weak-passwords-report.component.html', templateUrl: 'weak-passwords-report.component.html',
}) })
export class WeakPasswordsReportComponent extends CipherReportComponent implements OnInit { export class WeakPasswordsReportComponent extends CipherReportComponent implements OnInit {
passwordStrengthMap = new Map<string, [string, string]>(); passwordStrengthMap = new Map<string, [string, string]>();
private passwordStrengthCache = new Map<string, number>(); private passwordStrengthCache = new Map<string, number>();
@ -39,15 +40,22 @@ export class WeakPasswordsReportComponent extends CipherReportComponent implemen
async setCiphers() { async setCiphers() {
const allCiphers = await this.getAllCiphers(); const allCiphers = await this.getAllCiphers();
const weakPasswordCiphers: CipherView[] = []; const weakPasswordCiphers: CipherView[] = [];
const isUserNameNotEmpty = (c: CipherView): boolean => {
return c.login.username != null && c.login.username.trim() !== '';
}
const getCacheKey = (c:CipherView): string => {
return c.login.password + '_____' + (isUserNameNotEmpty(c) ? c.login.username : '');
}
allCiphers.forEach(c => { allCiphers.forEach(c => {
if (c.type !== CipherType.Login || c.login.password == null || c.login.password === '' || c.isDeleted) { if (c.type !== CipherType.Login || c.login.password == null || c.login.password === '' || c.isDeleted) {
return; return;
} }
const hasUsername = c.login.username != null && c.login.username.trim() !== ''; const hasUserName = isUserNameNotEmpty(c);
const cacheKey = c.login.password + '_____' + (hasUsername ? c.login.username : ''); const cacheKey = getCacheKey(c);
if (!this.passwordStrengthCache.has(cacheKey)) { if (!this.passwordStrengthCache.has(cacheKey)) {
let userInput: string[] = []; let userInput: string[] = [];
if (hasUsername) { if (hasUserName) {
const atPosition = c.login.username.indexOf('@'); const atPosition = c.login.username.indexOf('@');
if (atPosition > -1) { if (atPosition > -1) {
userInput = userInput.concat( userInput = userInput.concat(
@ -68,6 +76,10 @@ export class WeakPasswordsReportComponent extends CipherReportComponent implemen
weakPasswordCiphers.push(c); weakPasswordCiphers.push(c);
} }
}); });
weakPasswordCiphers.sort((a, b) => {
return this.passwordStrengthCache.get(getCacheKey(a)) -
this.passwordStrengthCache.get(getCacheKey(b));
});
this.ciphers = weakPasswordCiphers; this.ciphers = weakPasswordCiphers;
} }