1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-10 06:08:34 +02:00
bitwarden-browser/src/app/tools/exposed-passwords-report.component.ts

65 lines
2.1 KiB
TypeScript
Raw Normal View History

2018-12-12 04:09:16 +01:00
import {
Component,
ComponentFactoryResolver,
2018-12-12 15:29:51 +01:00
OnInit,
2018-12-12 04:09:16 +01:00
} from '@angular/core';
import { AuditService } from 'jslib/abstractions/audit.service';
import { CipherService } from 'jslib/abstractions/cipher.service';
2018-12-12 15:29:51 +01:00
import { MessagingService } from 'jslib/abstractions/messaging.service';
import { UserService } from 'jslib/abstractions/user.service';
2018-12-12 04:09:16 +01:00
import { CipherView } from 'jslib/models/view/cipherView';
import { CipherType } from 'jslib/enums/cipherType';
2018-12-12 15:11:10 +01:00
import { CipherReportComponent } from './cipher-report.component';
2018-12-12 04:09:16 +01:00
@Component({
selector: 'app-exposed-passwords-report',
templateUrl: 'exposed-passwords-report.component.html',
})
2018-12-12 15:29:51 +01:00
export class ExposedPasswordsReportComponent extends CipherReportComponent implements OnInit {
2018-12-12 04:09:16 +01:00
exposedPasswordMap = new Map<string, number>();
2018-12-14 19:56:01 +01:00
constructor(protected cipherService: CipherService, protected auditService: AuditService,
2018-12-12 15:29:51 +01:00
componentFactoryResolver: ComponentFactoryResolver, messagingService: MessagingService,
userService: UserService) {
super(componentFactoryResolver, userService, messagingService, true);
}
ngOnInit() {
2018-12-14 19:56:01 +01:00
this.checkAccess();
2018-12-12 15:29:51 +01:00
}
async load() {
2018-12-14 19:56:01 +01:00
if (await this.checkAccess()) {
2018-12-12 15:29:51 +01:00
super.load();
}
2018-12-12 15:11:10 +01:00
}
2018-12-12 04:09:16 +01:00
2018-12-12 15:11:10 +01:00
async setCiphers() {
2018-12-14 19:56:01 +01:00
const allCiphers = await this.getAllCiphers();
2018-12-12 04:09:16 +01:00
const exposedPasswordCiphers: CipherView[] = [];
const promises: Array<Promise<void>> = [];
allCiphers.forEach((c) => {
if (c.type !== CipherType.Login || c.login.password == null || c.login.password === '') {
return;
}
const promise = this.auditService.passwordLeaked(c.login.password).then((exposedCount) => {
if (exposedCount > 0) {
exposedPasswordCiphers.push(c);
this.exposedPasswordMap.set(c.id, exposedCount);
}
});
promises.push(promise);
});
await Promise.all(promises);
this.ciphers = exposedPasswordCiphers;
}
2018-12-14 19:56:01 +01:00
protected getAllCiphers(): Promise<CipherView[]> {
return this.cipherService.getAllDecrypted();
}
2018-12-12 04:09:16 +01:00
}