Blazorise PasswordStrength component
The PasswordStrength component combines a password input with configurable strength rules, a progress indicator, and localized guidance.
The default setup follows passphrase-first guidance: long passwords are prioritized, common or breached values are blocked, and character-composition rules remain optional.
To use the PasswordStrength component, install the Blazorise.Components package first.
Installation
PasswordStrength is part of the Blazorise.Components package and follows the same Blazorise licensing and copyright terms.
NuGet
Install extension from NuGet.dotnet add package Blazorise.Components
Imports
In your main_Imports.razor add:
@using Blazorise.Components
Security guidance
By default, PasswordStrength uses MinimumLength="15", checks blocked/common passwords, and does not force uppercase, lowercase, numeric, or symbol rules.
If your policy requires composition checks, enable the related parameters (RequireUppercase, RequireLowercase, RequireNumber, and RequireSpecialCharacter) and adjust MinimumLength as needed.
Examples
Basic
Start with the default passphrase-first configuration.<PasswordStrength @bind-Value="" Placeholder="Use a long passphrase" StrengthChanged="" /> <Div Margin="Margin.Is3.FromTop"> <Span TextWeight="TextWeight.SemiBold">Current score:</Span> @score% </Div>
@code { private string password; private int score; private void OnStrengthChanged( PasswordStrengthChangedEventArgs eventArgs ) { score = eventArgs.Score; } }
Custom policy
Configure a stricter policy with composition requirements and a custom blocked-password list.<PasswordStrength @bind-Value="" MinimumLength="12" RequireUppercase RequireLowercase RequireNumber RequireSpecialCharacter RequireNotCompromisedPassword BlockedPasswords="" />
@code { private static readonly string[] blockedPasswords = [ "P@ssw0rd", "Password123!", "Welcome123!" ]; private string password; }
Validation
UsePasswordStrength inside Validation and Validations just like any other text input.
@using System @using System.Linq <Validations @ref="" Mode="ValidationMode.Manual"> <Validation Validator=""> <Field> <FieldLabel RequiredIndicator>Password</FieldLabel> <FieldBody> <PasswordStrength @bind-Value="" MinimumLength="12" RequireUppercase RequireLowercase RequireNumber RequireSpecialCharacter> <Feedback> <ValidationError>Please enter a password that satisfies all active policy rules.</ValidationError> </Feedback> </PasswordStrength> </FieldBody> </Field> </Validation> <Button Color="Color.Primary" Clicked=""> Validate </Button> </Validations>
@code { private Validations validations; private string password; private void ValidatePasswordPolicy( ValidatorEventArgs eventArgs ) { string currentPassword = Convert.ToString( eventArgs.Value ); if ( string.IsNullOrWhiteSpace( currentPassword ) ) { eventArgs.Status = ValidationStatus.Error; return; } bool hasMinimumLength = currentPassword.Length >= 12; bool hasUppercase = currentPassword.Any( char.IsUpper ); bool hasLowercase = currentPassword.Any( char.IsLower ); bool hasNumber = currentPassword.Any( char.IsDigit ); bool hasSpecialCharacter = currentPassword.Any( c => char.IsPunctuation( c ) || char.IsSymbol( c ) ); bool isValid = hasMinimumLength && hasUppercase && hasLowercase && hasNumber && hasSpecialCharacter; eventArgs.Status = isValid ? ValidationStatus.Success : ValidationStatus.Error; } private Task ValidateAll() { return validations.ValidateAll(); } }
Custom localization
Override localized texts with thePasswordStrengthLocalizer parameter.
@using System.Collections.Generic @using System.Globalization <PasswordStrength @bind-Value="" MinimumLength="10" RequireNumber PasswordStrengthLocalizer="" />
@code { private static readonly Dictionary<string, string> customLocalization = new() { ["Enter password"] = "Enter your password", ["Strength"] = "Strength", ["Strong"] = "Excellent", ["Good"] = "Good", ["Fair"] = "Average", ["Weak"] = "Weak", ["Show password"] = "Show password", ["Hide password"] = "Hide password", ["At least {0} characters"] = "Use at least {0} characters", ["One number"] = "Include one number", ["Not a common or breached password"] = "Avoid common or breached passwords", }; private string password; private string Localize( string name, params object[] arguments ) { string template = customLocalization.TryGetValue( name, out string localizedText ) ? localizedText : name; return arguments?.Length > 0 ? string.Format( CultureInfo.CurrentCulture, template, arguments ) : template; } }
Licensing
For full licensing details, see the Blazorise License page.API
See the API reference for the parameters, events, methods, and related types available to the components covered on this page.