From 89dc3b70e1bb041ebe7c5c08bc9c34a154085a52 Mon Sep 17 00:00:00 2001 From: Naoaki Iwakiri Date: Tue, 6 Apr 2021 07:23:48 +0900 Subject: [PATCH] Sort weak passwords by severity (#446) * Sort weak passwords by weakness * Move static methods into local const --- .../tools/weak-passwords-report.component.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/app/tools/weak-passwords-report.component.ts b/src/app/tools/weak-passwords-report.component.ts index 826e544826..a522a693b4 100644 --- a/src/app/tools/weak-passwords-report.component.ts +++ b/src/app/tools/weak-passwords-report.component.ts @@ -20,6 +20,7 @@ import { CipherReportComponent } from './cipher-report.component'; templateUrl: 'weak-passwords-report.component.html', }) export class WeakPasswordsReportComponent extends CipherReportComponent implements OnInit { + passwordStrengthMap = new Map(); private passwordStrengthCache = new Map(); @@ -39,15 +40,22 @@ export class WeakPasswordsReportComponent extends CipherReportComponent implemen async setCiphers() { const allCiphers = await this.getAllCiphers(); 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 => { if (c.type !== CipherType.Login || c.login.password == null || c.login.password === '' || c.isDeleted) { return; } - const hasUsername = c.login.username != null && c.login.username.trim() !== ''; - const cacheKey = c.login.password + '_____' + (hasUsername ? c.login.username : ''); + const hasUserName = isUserNameNotEmpty(c); + const cacheKey = getCacheKey(c); if (!this.passwordStrengthCache.has(cacheKey)) { let userInput: string[] = []; - if (hasUsername) { + if (hasUserName) { const atPosition = c.login.username.indexOf('@'); if (atPosition > -1) { userInput = userInput.concat( @@ -68,6 +76,10 @@ export class WeakPasswordsReportComponent extends CipherReportComponent implemen weakPasswordCiphers.push(c); } }); + weakPasswordCiphers.sort((a, b) => { + return this.passwordStrengthCache.get(getCacheKey(a)) - + this.passwordStrengthCache.get(getCacheKey(b)); + }); this.ciphers = weakPasswordCiphers; }