From 4435c5bccf88828f684efd7b095e6e6c44286363 Mon Sep 17 00:00:00 2001 From: Gbubemi Smith Date: Tue, 23 Aug 2022 22:27:40 +0100 Subject: [PATCH] Fixed defect (#3344) --- .../password-strength.component.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libs/angular/src/shared/components/password-strength/password-strength.component.ts b/libs/angular/src/shared/components/password-strength/password-strength.component.ts index 8630099d65..e14284eb75 100644 --- a/libs/angular/src/shared/components/password-strength/password-strength.component.ts +++ b/libs/angular/src/shared/components/password-strength/password-strength.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from "@angular/core"; +import { Component, EventEmitter, Input, OnChanges, Output } from "@angular/core"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service"; @@ -15,9 +15,10 @@ export interface PasswordColorText { export class PasswordStrengthComponent implements OnChanges { @Input() showText = false; @Input() email: string; - @Input() password: string; @Input() name: string; - + @Input() set password(value: string) { + this.updatePasswordStrength(value); + } @Output() passwordStrengthResult = new EventEmitter(); @Output() passwordScoreColor = new EventEmitter(); @@ -61,10 +62,8 @@ export class PasswordStrengthComponent implements OnChanges { private passwordGenerationService: PasswordGenerationService ) {} - ngOnChanges(changes: SimpleChanges): void { + ngOnChanges(): void { this.masterPasswordStrengthTimeout = setTimeout(() => { - this.updatePasswordStrength(changes.password?.currentValue); - this.scoreWidth = this.masterPasswordScore == null ? 0 : (this.masterPasswordScore + 1) * 20; switch (this.masterPasswordScore) { @@ -87,7 +86,7 @@ export class PasswordStrengthComponent implements OnChanges { } this.setPasswordScoreText(this.color, this.text); - }, 100); + }, 300); } updatePasswordStrength(password: string) { @@ -102,7 +101,6 @@ export class PasswordStrengthComponent implements OnChanges { this.getPasswordStrengthUserInput() ); this.passwordStrengthResult.emit(strengthResult); - this.masterPasswordScore = strengthResult == null ? null : strengthResult.score; } @@ -110,7 +108,7 @@ export class PasswordStrengthComponent implements OnChanges { let userInput: string[] = []; const email = this.email; const name = this.name; - const atPosition = email.indexOf("@"); + const atPosition = email?.indexOf("@"); if (atPosition > -1) { userInput = userInput.concat( email