1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-25 12:43:36 +00:00

sort and limit password history parsing

This commit is contained in:
Kyle Spearrin
2019-03-25 09:10:33 -04:00
parent 8ed27eeeec
commit 58c34b896c
2 changed files with 99 additions and 75 deletions

View File

@@ -79,21 +79,11 @@ export class OnePassword1PifImporter extends BaseImporter implements Importer {
});
}
if (item.details.passwordHistory != null) {
this.processPasswordHistory(item.details.passwordHistory, cipher);
this.parsePasswordHistory(item.details.passwordHistory, cipher);
}
}
}
private processPasswordHistory(items: any[], cipher: CipherView) {
cipher.passwordHistory = cipher.passwordHistory || [];
items.forEach((entry: any) => {
const phv = new PasswordHistoryView();
phv.password = entry.value;
phv.lastUsedDate = new Date(entry.time * 1000);
cipher.passwordHistory.push(phv);
});
}
private processStandardItem(item: any, cipher: CipherView) {
cipher.favorite = item.openContents && item.openContents.faveIndex ? true : false;
cipher.name = this.getValueOrDefault(item.title);
@@ -143,11 +133,21 @@ export class OnePassword1PifImporter extends BaseImporter implements Importer {
});
}
if (item.secureContents.passwordHistory != null) {
this.processPasswordHistory(item.secureContents.passwordHistory, cipher);
this.parsePasswordHistory(item.secureContents.passwordHistory, cipher);
}
}
}
private parsePasswordHistory(items: any[], cipher: CipherView) {
const maxSize = items.length > 5 ? 5 : items.length;
cipher.passwordHistory = items.sort((a, b) => b.time - a.time).slice(0, maxSize).map((entry: any) => {
const ph = new PasswordHistoryView();
ph.password = entry.value;
ph.lastUsedDate = new Date(entry.time * 1000);
return ph;
});
}
private parseFields(fields: any[], cipher: CipherView, designationKey: string, valueKey: string, nameKey: string) {
fields.forEach((field: any) => {
if (field[valueKey] == null || field[valueKey].toString().trim() === '') {