1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 09:13:33 +00:00

reused passwords report

This commit is contained in:
Kyle Spearrin
2018-12-11 14:47:41 -05:00
parent 4222b192c4
commit 0ebf30b8b6
6 changed files with 166 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
import {
Component,
ComponentFactoryResolver,
OnInit,
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { CipherView } from 'jslib/models/view/cipherView';
import { CipherType } from 'jslib/enums/cipherType';
import { ModalComponent } from '../modal.component';
import { AddEditComponent } from '../vault/add-edit.component';
@Component({
selector: 'app-reused-passwords-report',
templateUrl: 'reused-passwords-report.component.html',
})
export class ReusedPasswordsReportComponent implements OnInit {
@ViewChild('cipherAddEdit', { read: ViewContainerRef }) cipherAddEditModalRef: ViewContainerRef;
loading = true;
hasLoaded = false;
ciphers: CipherView[] = [];
passwordUseMap: Map<string, number>;
private modal: ModalComponent = null;
constructor(private ciphersService: CipherService, private componentFactoryResolver: ComponentFactoryResolver) { }
async ngOnInit() {
this.load();
this.hasLoaded = true;
}
async load() {
this.loading = true;
const allCiphers = await this.ciphersService.getAllDecrypted();
const ciphersWithPasswords: CipherView[] = [];
this.passwordUseMap = new Map<string, number>();
allCiphers.forEach((c) => {
if (c.type !== CipherType.Login || c.login.password == null || c.login.password === '') {
return;
}
ciphersWithPasswords.push(c);
if (this.passwordUseMap.has(c.login.password)) {
this.passwordUseMap.set(c.login.password, this.passwordUseMap.get(c.login.password) + 1);
} else {
this.passwordUseMap.set(c.login.password, 1);
}
});
this.ciphers = ciphersWithPasswords.filter((c) =>
this.passwordUseMap.has(c.login.password) && this.passwordUseMap.get(c.login.password) > 1);
this.loading = false;
}
selectCipher(cipher: CipherView) {
if (this.modal != null) {
this.modal.close();
}
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
this.modal = this.cipherAddEditModalRef.createComponent(factory).instance;
const childComponent = this.modal.show<AddEditComponent>(
AddEditComponent, this.cipherAddEditModalRef);
childComponent.cipherId = cipher == null ? null : cipher.id;
childComponent.onSavedCipher.subscribe(async (c: CipherView) => {
this.modal.close();
await this.load();
});
childComponent.onDeletedCipher.subscribe(async (c: CipherView) => {
this.modal.close();
await this.load();
});
this.modal.onClosed.subscribe(() => {
this.modal = null;
});
return childComponent;
}
}