This an Angular 2 implementation of AngularJS Directive to test the strength of a password.
If you are using Angular 9+ you will need to use ng9-password-strength-bar.
The only configuration differences between the ng2 and ng9 versions are these name changes:
npm install ng2-password-strength-bar --save
If you upgrade from v1.0.x to v1.1.x (or greater) you will need to change the PasswordStrengthBar import. There are two options:
import { PasswordStrengthBarModule } from 'ng2-password-strength-bar';
//...
@NgModule({
//...
declarations: [
AppComponent,
//...
],
imports: [
BrowserModule,
FormsModule,
PasswordStrengthBarModule,
//...
//...
})
export class AppModule {}
@Component({
selector: 'my-app',
template: `
<h3>Angular 2 Password Strength Bar</h3>
<div>
<form name="myForm" novalidate>
<input type="password" class="form-control" id="password" name="password" placeholder="Enter password"
[(ngModel)]="account.password" #password="ngModel"
minlength="5" maxlength="50" required>
<ng2-password-strength-bar
[passwordToCheck]="account.password"
[barLabel]="barLabel"
[barColors]="myColors">
</ng2-password-strength-bar>
</form>
</div>
`,
})
export class App {
public account = {
password: <string>null
};
public barLabel: string = "Password strength:";
public myColors = ['#DD2C00', '#FF6D00', '#FFD600', '#AEEA00', '#00C853'];
// ...
}
<ng2-password-strength-bar
[passwordToCheck]="account.password"
[barLabel]="barLabel"
[barColors]="myColors"
[baseColor]="baseColor"
[strengthLabels]="strengthLabels"
(onStrengthChanged)="strengthChanged($event)">
</ng2-password-strength-bar>
(New in v1.2.0)
colors[0]
, ..., the highest picks colors[4]
.['#F00', '#F90', '#FF0', '#9F0', '#0F0']
(New in v1.2.1)
public baseColor = '#FFF';
(New in v1.2.1)
public strengthLabels = ['(Useless)', '(Weak)', '(Normal)', '(Strong)', '(Great!)'];
strengthChanged(strength: number) {
this.strength = strength;
}
git clone https://github.com/rnadler/ng2-password-strength-bar.git
cd ng2-password-strength-bar
npm install
npm start
# Browser should open automatically on http://localhost:3000npm run test-once
# Defaults to a Firefox browser