2018-12-11 20:47:41 +01:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
ComponentFactoryResolver,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
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-11 20:47:41 +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-11 20:47:41 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-reused-passwords-report',
|
|
|
|
templateUrl: 'reused-passwords-report.component.html',
|
|
|
|
})
|
2018-12-12 15:11:10 +01:00
|
|
|
export class ReusedPasswordsReportComponent extends CipherReportComponent implements OnInit {
|
2018-12-11 20:47:41 +01:00
|
|
|
passwordUseMap: Map<string, number>;
|
|
|
|
|
2018-12-14 20:42:04 +01:00
|
|
|
constructor(protected cipherService: CipherService, componentFactoryResolver: ComponentFactoryResolver,
|
2018-12-12 15:29:51 +01:00
|
|
|
messagingService: MessagingService, userService: UserService) {
|
|
|
|
super(componentFactoryResolver, userService, messagingService, true);
|
2018-12-12 15:11:10 +01:00
|
|
|
}
|
2018-12-11 20:47:41 +01:00
|
|
|
|
2018-12-12 15:29:51 +01:00
|
|
|
async ngOnInit() {
|
2018-12-14 19:56:01 +01:00
|
|
|
if (await this.checkAccess()) {
|
2018-12-12 15:29:51 +01:00
|
|
|
await super.load();
|
|
|
|
}
|
2018-12-11 20:47:41 +01:00
|
|
|
}
|
|
|
|
|
2018-12-12 15:11:10 +01:00
|
|
|
async setCiphers() {
|
2018-12-14 20:42:04 +01:00
|
|
|
const allCiphers = await this.getAllCiphers();
|
2018-12-11 20:47:41 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2018-12-11 21:16:45 +01:00
|
|
|
const reusedPasswordCiphers = ciphersWithPasswords.filter((c) =>
|
2018-12-11 20:47:41 +01:00
|
|
|
this.passwordUseMap.has(c.login.password) && this.passwordUseMap.get(c.login.password) > 1);
|
2018-12-11 21:16:45 +01:00
|
|
|
this.ciphers = reusedPasswordCiphers;
|
2018-12-11 20:47:41 +01:00
|
|
|
}
|
2018-12-14 20:42:04 +01:00
|
|
|
|
|
|
|
protected getAllCiphers(): Promise<CipherView[]> {
|
|
|
|
return this.cipherService.getAllDecrypted();
|
|
|
|
}
|
2018-12-11 20:47:41 +01:00
|
|
|
}
|