2018-12-11 23:49:51 +01:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
ComponentFactoryResolver,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
|
|
|
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
|
|
|
|
|
|
|
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 23:49:51 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-weak-passwords-report',
|
|
|
|
templateUrl: 'weak-passwords-report.component.html',
|
|
|
|
})
|
2018-12-12 15:11:10 +01:00
|
|
|
export class WeakPasswordsReportComponent extends CipherReportComponent implements OnInit {
|
2018-12-11 23:49:51 +01:00
|
|
|
passwordStrengthMap = new Map<string, [string, string]>();
|
|
|
|
|
|
|
|
constructor(private ciphersService: CipherService, private passwordGenerationService: PasswordGenerationService,
|
2018-12-12 15:11:10 +01:00
|
|
|
componentFactoryResolver: ComponentFactoryResolver) {
|
|
|
|
super(componentFactoryResolver);
|
|
|
|
}
|
2018-12-11 23:49:51 +01:00
|
|
|
|
2018-12-12 15:11:10 +01:00
|
|
|
ngOnInit() {
|
|
|
|
this.load();
|
2018-12-11 23:49:51 +01:00
|
|
|
}
|
|
|
|
|
2018-12-12 15:11:10 +01:00
|
|
|
async setCiphers() {
|
2018-12-11 23:49:51 +01:00
|
|
|
const allCiphers = await this.ciphersService.getAllDecrypted();
|
|
|
|
const weakPasswordCiphers: CipherView[] = [];
|
|
|
|
allCiphers.forEach((c) => {
|
|
|
|
if (c.type !== CipherType.Login || c.login.password == null || c.login.password === '') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const result = this.passwordGenerationService.passwordStrength(c.login.password);
|
|
|
|
if (result.score <= 3) {
|
|
|
|
this.passwordStrengthMap.set(c.id, this.scoreKey(result.score));
|
|
|
|
weakPasswordCiphers.push(c);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.ciphers = weakPasswordCiphers;
|
|
|
|
}
|
|
|
|
|
|
|
|
private scoreKey(score: number): [string, string] {
|
|
|
|
switch (score) {
|
|
|
|
case 4:
|
|
|
|
return ['strong', 'success'];
|
|
|
|
case 3:
|
|
|
|
return ['good', 'primary'];
|
|
|
|
case 2:
|
|
|
|
return ['weak', 'warning'];
|
|
|
|
default:
|
|
|
|
return ['veryWeak', 'danger'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|