From 539ee0b1b6c13904466d88a4dafa5f59dcc65d34 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 6 Aug 2018 13:37:29 -0400 Subject: [PATCH] detect password change on login --- jslib | 2 +- src/background/runtime.background.ts | 43 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/jslib b/jslib index 49d3f227042..3429b57db42 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 49d3f227042bc090dec48f83bbbf7da3029828a5 +Subproject commit 3429b57db42a3e1e9948b870bf24fcc02ebc8a99 diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 08b81d758e8..ca45d1984f6 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -278,15 +278,8 @@ export default class RuntimeBackground { } const ciphers = await this.cipherService.getAllDecryptedForUrl(loginInfo.url); - let match = false; - for (let i = 0; i < ciphers.length; i++) { - if (ciphers[i].login.username === loginInfo.username) { - match = true; - break; - } - } - - if (!match) { + const usernameMatches = ciphers.filter((c) => c.login.username === loginInfo.username); + if (usernameMatches.length === 0) { // remove any old messages for this tab this.removeTabFromNotificationQueue(tab); this.main.notificationQueue.push({ @@ -299,6 +292,8 @@ export default class RuntimeBackground { expires: new Date((new Date()).getTime() + 30 * 60000), // 30 minutes }); await this.main.checkNotificationQueue(tab); + } else if (usernameMatches.length === 1 && usernameMatches[0].login.password !== loginInfo.password) { + this.addChangedPasswordToQueue(usernameMatches[0].id, loginDomain, loginInfo.password, tab); } } @@ -309,22 +304,26 @@ export default class RuntimeBackground { } const ciphers = await this.cipherService.getAllDecryptedForUrl(changeData.url); - const matches = ciphers.filter((c) => c.login.password === changeData.currentPassword); - if (matches.length === 1) { - // remove any old messages for this tab - this.removeTabFromNotificationQueue(tab); - this.main.notificationQueue.push({ - type: 'changePassword', - cipherId: matches[0].id, - newPassword: changeData.newPassword, - domain: loginDomain, - tabId: tab.id, - expires: new Date((new Date()).getTime() + 30 * 60000), // 30 minutes - }); - await this.main.checkNotificationQueue(tab); + const passwordMatches = ciphers.filter((c) => c.login.password === changeData.currentPassword); + if (passwordMatches.length === 1) { + this.addChangedPasswordToQueue(passwordMatches[0].id, loginDomain, changeData.newPassword, tab); } } + private async addChangedPasswordToQueue(cipherId: string, loginDomain: string, newPassword: string, tab: any) { + // remove any old messages for this tab + this.removeTabFromNotificationQueue(tab); + this.main.notificationQueue.push({ + type: 'changePassword', + cipherId: cipherId, + newPassword: newPassword, + domain: loginDomain, + tabId: tab.id, + expires: new Date((new Date()).getTime() + 30 * 60000), // 30 minutes + }); + await this.main.checkNotificationQueue(tab); + } + private removeTabFromNotificationQueue(tab: any) { for (let i = this.main.notificationQueue.length - 1; i >= 0; i--) { if (this.main.notificationQueue[i].tabId === tab.id) {