2021-12-17 15:57:11 +01:00
|
|
|
import { Component, Input, OnChanges } from "@angular/core";
|
2018-11-13 04:54:40 +01:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
2018-11-13 04:54:40 +01:00
|
|
|
|
|
|
|
@Component({
|
2021-12-17 15:57:11 +01:00
|
|
|
selector: "app-password-strength",
|
|
|
|
templateUrl: "password-strength.component.html",
|
2018-11-13 04:54:40 +01:00
|
|
|
})
|
|
|
|
export class PasswordStrengthComponent implements OnChanges {
|
2022-01-27 18:25:58 +01:00
|
|
|
@Input() score?: number;
|
|
|
|
@Input() showText = false;
|
2018-11-13 04:54:40 +01:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
scoreWidth = 0;
|
|
|
|
color = "bg-danger";
|
|
|
|
text: string;
|
2018-11-13 04:54:40 +01:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
constructor(private i18nService: I18nService) {}
|
2018-11-13 04:54:40 +01:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
ngOnChanges(): void {
|
|
|
|
this.scoreWidth = this.score == null ? 0 : (this.score + 1) * 20;
|
|
|
|
switch (this.score) {
|
|
|
|
case 4:
|
|
|
|
this.color = "bg-success";
|
|
|
|
this.text = this.i18nService.t("strong");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
this.color = "bg-primary";
|
|
|
|
this.text = this.i18nService.t("good");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
this.color = "bg-warning";
|
|
|
|
this.text = this.i18nService.t("weak");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.color = "bg-danger";
|
|
|
|
this.text = this.score != null ? this.i18nService.t("weak") : null;
|
|
|
|
break;
|
2018-11-13 04:54:40 +01:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-11-13 04:54:40 +01:00
|
|
|
}
|