Skip to content

Commit 3968d12

Browse files
committed
feat(package): implemented the password strength api #191
1 parent e8686f9 commit 3968d12

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/module/components/ngx-auth-firebaseui/auth.component.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@
9191
<!--labels will work only with @angular/material@6.2.0 -->
9292
<mat-label>{{nameText}}</mat-label>
9393
<input matInput
94-
minlength="2"
95-
maxlength="30"
94+
[minlength]="passwordStrength.min.toString()"
95+
[maxlength]="passwordStrength.max.toString()"
9696
[formControl]="sigUpNameFormControl"
9797
required>
9898
<mat-icon matSuffix [color]="color">person</mat-icon>
9999
<mat-hint align="end" aria-live="polite">
100-
{{signUpFormGroup.value.name?.length}} / 25
100+
{{signUpFormGroup.value.name?.length}} / {{passwordStrength.max}}
101101
</mat-hint>
102102
<mat-error *ngIf="sigUpNameFormControl.hasError('required')">
103103
{{nameErrorRequiredText}}
@@ -157,6 +157,14 @@
157157
</mat-form-field>
158158

159159
<mat-password-strength #passwordStrength
160+
[min]="min"
161+
[max]="max"
162+
[customValidator]="customValidator"
163+
[enableLengthRule]="enableLengthRule"
164+
[enableLowerCaseLetterRule]="enableLowerCaseLetterRule"
165+
[enableUpperCaseLetterRule]="enableUpperCaseLetterRule"
166+
[enableDigitRule]="enableDigitRule"
167+
[enableSpecialCharRule]="enableSpecialCharRule"
160168
[password]="signUpFormGroup.value.password"
161169
[externalError]="sigUpPasswordFormControl.dirty">
162170
</mat-password-strength>
@@ -201,7 +209,7 @@
201209
</mat-tab>
202210

203211
<!--Reset password tab-->
204-
<mat-tab *ngIf="passwordResetWished" [label]="resetPasswordTabText" >
212+
<mat-tab *ngIf="passwordResetWished" [label]="resetPasswordTabText">
205213
<form [formGroup]="resetPasswordFormGroup" (ngSubmit)="resetPasswordFormGroup.valid && resetPassword()">
206214

207215
<mat-card>

src/module/components/ngx-auth-firebaseui/auth.component.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
ViewChild
1313
} from '@angular/core';
1414
import {AbstractControl, FormControl, FormGroup, Validators} from '@angular/forms';
15-
import {MatDialog, MatDialogRef, MatFormFieldAppearance, MatTabChangeEvent, MatTabGroup} from '@angular/material';
15+
import {MatDialog, MatDialogRef, MatFormFieldAppearance, MatTabChangeEvent, MatTabGroup, ThemePalette} from '@angular/material';
1616
import {AngularFireAuth} from '@angular/fire/auth';
1717
import {isPlatformBrowser} from '@angular/common';
1818
import {Subscription} from 'rxjs/internal/Subscription';
@@ -22,6 +22,7 @@ import {LegalityDialogComponent} from '../../components/legality-dialog/legality
2222
import {LegalityDialogParams, LegalityDialogResult} from '../../interfaces/legality.dialog.intreface';
2323
import {NgxAuthFirebaseUIConfig, NgxAuthFirebaseUIConfigToken} from '../../ngx-auth-firebase-u-i.module';
2424
import {defaultAuthFirebaseUIConfig} from '../../interfaces/config.interface';
25+
import {MatPasswordStrengthComponent} from '@angular-material-extensions/password-strength';
2526

2627

2728
export const EMAIL_REGEX = new RegExp(['^(([^<>()[\\]\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\.,;:\\s@\"]+)*)',
@@ -40,6 +41,7 @@ export const PHONE_NUMBER_REGEX = new RegExp(/^\+(?:[0-9] ?){6,14}[0-9]$/);
4041
export class AuthComponent implements OnInit, OnChanges, OnDestroy {
4142

4243
@ViewChild(MatTabGroup, {static: false}) matTabGroup: MatTabGroup;
44+
@ViewChild(MatPasswordStrengthComponent, {static: false}) passwordStrength: MatPasswordStrengthComponent;
4345

4446
@Input() providers: string[] | string = AuthProvider.ALL; // google, facebook, twitter, github as array or all as one single string
4547
@Input() appearance: MatFormFieldAppearance;
@@ -53,6 +55,17 @@ export class AuthComponent implements OnInit, OnChanges, OnDestroy {
5355
@Input() messageOnAuthSuccess: string;
5456
@Input() messageOnAuthError: string;
5557

58+
// Password strength api
59+
@Input() enableLengthRule = true;
60+
@Input() enableLowerCaseLetterRule = true;
61+
@Input() enableUpperCaseLetterRule = true;
62+
@Input() enableDigitRule = true;
63+
@Input() enableSpecialCharRule = true;
64+
@Input() min = 8;
65+
@Input() max = 30;
66+
@Input() customValidator: RegExp;
67+
@Output() onStrengthChanged: EventEmitter<number> = new EventEmitter();
68+
5669
// Customize the text
5770
// Reset Password Tab
5871
@Input() resetPasswordTabText = 'Reset e-mail address to password';
@@ -127,6 +140,7 @@ export class AuthComponent implements OnInit, OnChanges, OnDestroy {
127140

128141
public ngOnInit(): void {
129142
this.config = Object.assign(defaultAuthFirebaseUIConfig, this.config);
143+
this.onStrengthChanged = this.passwordStrength.onStrengthChanged;
130144

131145
if (isPlatformBrowser(this.platformId)) {
132146
this.onErrorSubscription = this.onError.subscribe(() => this.authenticationError = true);
@@ -154,7 +168,7 @@ export class AuthComponent implements OnInit, OnChanges, OnDestroy {
154168
this.selectedTabChange.emit(event);
155169
}
156170

157-
get color(): string {
171+
get color(): string | ThemePalette {
158172
return this.authenticationError ? 'warn' : 'primary';
159173
}
160174

0 commit comments

Comments
 (0)