2018-12-11 23:49:51 +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';
|
2018-12-11 23:49:51 +01:00
|
|
|
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
2018-12-12 15:29:51 +01:00
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
2018-12-11 23:49:51 +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 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]>();
|
|
|
|
|
2018-12-12 17:22:11 +01:00
|
|
|
private passwordStrengthCache = new Map<string, number>();
|
|
|
|
|
2018-12-11 23:49:51 +01:00
|
|
|
constructor(private ciphersService: CipherService, private passwordGenerationService: PasswordGenerationService,
|
2018-12-12 15:29:51 +01:00
|
|
|
componentFactoryResolver: ComponentFactoryResolver, messagingService: MessagingService,
|
|
|
|
userService: UserService) {
|
|
|
|
super(componentFactoryResolver, userService, messagingService, true);
|
2018-12-12 15:11:10 +01:00
|
|
|
}
|
2018-12-11 23:49:51 +01:00
|
|
|
|
2018-12-12 15:29:51 +01:00
|
|
|
async ngOnInit() {
|
|
|
|
if (await this.checkPremium()) {
|
|
|
|
await super.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;
|
|
|
|
}
|
2018-12-12 17:22:11 +01:00
|
|
|
if (!this.passwordStrengthCache.has(c.login.password)) {
|
2018-12-12 16:34:05 +01:00
|
|
|
const result = this.passwordGenerationService.passwordStrength(c.login.password);
|
2018-12-12 17:22:11 +01:00
|
|
|
this.passwordStrengthCache.set(c.login.password, result.score);
|
|
|
|
}
|
|
|
|
const score = this.passwordStrengthCache.get(c.login.password);
|
|
|
|
if (score != null && score <= 3) {
|
|
|
|
this.passwordStrengthMap.set(c.id, this.scoreKey(score));
|
|
|
|
weakPasswordCiphers.push(c);
|
|
|
|
}
|
2018-12-11 23:49:51 +01:00
|
|
|
});
|
|
|
|
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'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|