From 912e1cf89f0dacd803cbf62101d1a2d66a62bc55 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 12 Nov 2018 23:26:00 -0500 Subject: [PATCH] getPasswordStrengthUserInput on password change --- jslib | 2 +- src/app/settings/change-password.component.ts | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/jslib b/jslib index aa16fb2a9e..c297728967 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit aa16fb2a9e4b6fb33ed80dea2a4c7bfa2234d45c +Subproject commit c297728967bc12d7d4444b171a7d1fd79b68ec7d diff --git a/src/app/settings/change-password.component.ts b/src/app/settings/change-password.component.ts index edd5b6b4be..a84415c66a 100644 --- a/src/app/settings/change-password.component.ts +++ b/src/app/settings/change-password.component.ts @@ -1,5 +1,6 @@ import { Component, + OnInit, } from '@angular/core'; import { ToasterService } from 'angular2-toaster'; @@ -19,7 +20,7 @@ import { PasswordRequest } from 'jslib/models/request/passwordRequest'; selector: 'app-change-password', templateUrl: 'change-password.component.html', }) -export class ChangePasswordComponent { +export class ChangePasswordComponent implements OnInit { currentMasterPassword: string; newMasterPassword: string; confirmNewMasterPassword: string; @@ -27,6 +28,7 @@ export class ChangePasswordComponent { masterPasswordScore: number; private masterPasswordStrengthTimeout: any; + private email: string; constructor(private apiService: ApiService, private i18nService: I18nService, private analytics: Angulartics2, private toasterService: ToasterService, @@ -34,6 +36,10 @@ export class ChangePasswordComponent { private userService: UserService, private passwordGenerationService: PasswordGenerationService, private platformUtilsService: PlatformUtilsService) { } + async ngOnInit() { + this.email = await this.userService.getEmail(); + } + async submit() { const hasEncKey = await this.cryptoService.hasEncKey(); if (!hasEncKey) { @@ -58,7 +64,8 @@ export class ChangePasswordComponent { return; } - const strengthResult = this.passwordGenerationService.passwordStrength(this.newMasterPassword, null); + const strengthResult = this.passwordGenerationService.passwordStrength(this.newMasterPassword, + this.getPasswordStrengthUserInput()); if (strengthResult != null && strengthResult.score < 3) { const result = await this.platformUtilsService.showDialog(this.i18nService.t('weakMasterPasswordDesc'), this.i18nService.t('weakMasterPassword'), this.i18nService.t('yes'), this.i18nService.t('no'), @@ -92,8 +99,18 @@ export class ChangePasswordComponent { clearTimeout(this.masterPasswordStrengthTimeout); } this.masterPasswordStrengthTimeout = setTimeout(() => { - const strengthResult = this.passwordGenerationService.passwordStrength(this.newMasterPassword, null); + const strengthResult = this.passwordGenerationService.passwordStrength(this.newMasterPassword, + this.getPasswordStrengthUserInput()); this.masterPasswordScore = strengthResult == null ? null : strengthResult.score; }, 300); } + + private getPasswordStrengthUserInput() { + let userInput: string[] = []; + const atPosition = this.email.indexOf('@'); + if (atPosition > -1) { + userInput = userInput.concat(this.email.substr(0, atPosition).trim().toLowerCase().split(/[^A-Za-z0-9]/)); + } + return userInput; + } }