angular-password-strength-meter-package
v18.0.1
Published
[](https://github.com/bazobehram/password-strength-meter/actions/workflows/ci-workflow.yml) []="password" type="password" placeholder="Enter password" />
<password-strength-meter [password]="password" enableFeedback></password-strength-meter>
`,
})
export class AppComponent {
password: string = '';
}Step 2: Configure zxcvbn Service
To enable the default zxcvbn service for password strength estimation, configure your application as shown below:
import { bootstrapApplication } from '@angular/platform-browser';
import { ApplicationConfig } from '@angular/core';
import { provideZxvbnServiceForPSM } from 'password-strength-meter/zxcvbn';
export const appConfig: ApplicationConfig = {
providers: [provideZxvbnServiceForPSM()],
};
bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));Customization
Override zxcvbn Options
You can customize the zxcvbn service by providing a custom configuration:
import { translations } from '@zxcvbn-ts/language-en';
import { provideZxvbnServiceForPSM, ZxvbnConfigType } from 'password-strength-meter/zxcvbn';
const zxvbnConfig: ZxvbnConfigType = {
translations: translations,
};
export const appConfig: ApplicationConfig = {
providers: [provideZxvbnServiceForPSM(zxvbnConfig)],
};Customize the Password Strength Service
You can override the default password strength meter service by implementing the IPasswordStrengthMeterService interface.
import { Injectable } from '@angular/core';
import { IPasswordStrengthMeterService, FeedbackResult } from 'password-strength-meter';
@Injectable()
export class CustomPasswordStrengthService extends IPasswordStrengthMeterService {
score(password: string): number {
return password.length > 10 ? 4 : 2;
}
scoreWithFeedback(password: string): FeedbackResult {
return {
score: this.score(password),
feedback: { warning: '', suggestions: [] },
};
}
}API Reference
| Property | Bind | Type | Default Value | Description |
|--------------------------|:--------:|:--------:|---------------------------------------------------|--------------------------------------------------------------------------------------------------|
| password | Input() | string | null | The password string to evaluate. |
| minPasswordLength | Input() | number | 8 | Minimum password length to evaluate. |
| enableFeedback | Input() | boolean | false | Whether to show feedback messages for strength evaluation. |
| numberOfProgressBarItems | Input() | number | 5 | The number of segments in the progress bar. |
| enableAsync | Input() | boolean | false | Whether to calculate password strength asynchronously. |
| colors | Input() | string[] | ['darkred', 'orangered', 'orange', 'yellowgreen', 'green'] | Custom colors for progress bar segments, matching password strength levels (0–4). |
| strengthChange | Output() | number | null | Emits the calculated strength score for the provided password (0–4). |
License
This project is licensed under the MIT License.
