docs/en/framework/ui/angular/password-complexity-indicator-component.md
//[doc-seo]
{
"Description": "Learn how to implement the Password Complexity Indicator in your app with default settings for colors, texts, and requirements to enhance user security."
}
The PasswordComplexityIndicatorService is for calculating the password complexity.
Set default values in PasswordComplexityIndicatorService:
How we set default values
colors: string[] = ['#B0284B', '#F2A34F', '#5588A4', '#3E5CF6', '#6EBD70'];
texts: string[] = ['Weak', 'Fair', 'Normal', 'Good', 'Strong'];
requirements: RegexRequirementsModel = {
minLengthRegex: /(?=.{6,})/, // Default min length 6
numberRegex: /(?=.*[0-9])/, // Default isContain number
lowercaseRegex: /(?=.*[a-z ])/, // Default isContainLowercase
uppercaseRegex: /(?=.*[A-Z])/, // Default isContainUppercase
specialCharacterRegex: /[^a-zA-Z0-9 ]+/, // Default isContainSpecialCharacter
};
Make sure that the lengths of these values are equal (In our service we have 5 tests/colors/texts).
The PasswordComplexityIndicatorService has only one method validatePassword that passes the password as an argument and returns the properties of the bar.
The validatePassword method returns an object of the type ProgressBarStats.
interface ProgressBarStats{
bgColor: string,
text?: string,
width: number
})
Use this object to modify the password complexity bar
It's easy, imagine you have a password input that you want to add the complexity indicator under. Put this component under the input
<abp-password-complexity-indicator [progressBar]="ProgressBarStatsObject" />
validatePassword method of the PasswordComplexityIndicatorService, and bind return the value to the progressBar property of the abp-password-complexity-indicator ....
"Strength": "Strength",
"Weak": "Weak!",
"Fair": "Fair.",
"Normal": "Normal.",
"Good": "Good.",
"Strong": "Strong!"
colors,texts,regex in the PasswordComplexityIndicatorService are equal. Otherwise, it won't work.