MyPasswordStrength.Blazor 1.0.0

dotnet add package MyPasswordStrength.Blazor --version 1.0.0
                    
NuGet\Install-Package MyPasswordStrength.Blazor -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MyPasswordStrength.Blazor" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MyPasswordStrength.Blazor" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MyPasswordStrength.Blazor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MyPasswordStrength.Blazor --version 1.0.0
                    
#r "nuget: MyPasswordStrength.Blazor, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MyPasswordStrength.Blazor@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MyPasswordStrength.Blazor&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MyPasswordStrength.Blazor&version=1.0.0
                    
Install as a Cake Tool

MyPasswordStrength.Blazor

.NET Build & Test

A .NET Blazor library for validating password strength based on customizable complexity requirements.

Define your password strength complexity requirements with ease using the library.

The library supports multilingual password strength validation too.

You can configure:

  • Desired language
  • Minimum length
  • Minimum upper case characters
  • Minimum lower case characters
  • Minimum digits
  • Minimum special characters
  • Maximum same consecutive characters - eg aaa
  • Maximum consecutive ascending and/or descending digits - eg 123 / 654
  • Maximum consecutive ascending and/or descending characters - eg aBCd / DcbA
  • Repeated sequence check - eg in P@ssword@s - @s is repeating sequence

Background

The package provides a PasswordStrength Component and a PasswordStrengthAttribute data annotation that you can use to validate passwords in your .NET Blazor applications.

Component

The Component hooks into Blazor's form validation system and provides real-time feedback on password strength as the user types.

You can set the password strength requirements through the properties of the MyPasswordStrengthOptions class and pass the options to the Component.

The special characters considered in the validation are: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~.

You can modify this set of special characters by setting the SpecialCharacters property of the options to a custom string of special characters.

Sample Usage

The User model

using System.ComponentModel.DataAnnotations;

namespace YourNamespace.Models
{
    public class UserModel
    {
        [Required(ErrorMessage = "Username is required")]
        public string Username { get; set; } = string.Empty;

        [Required(ErrorMessage = "Password is required")]
        public string Password { get; set; } = string.Empty;
    }
}

Razor page

Registration.razor:

@page "/"
@using MyPasswordStrength.Blazor
@using Models

<PageTitle>Registration</PageTitle>

<EditForm Model="@user" OnValidSubmit="HandleValidSubmit">
    <DataAnnotationsValidator />
    <ValidationSummary />

    <div>
        <label>Username:</label>
        <InputText @bind-Value="user.Username" class="form-control" placeholder="Enter username" />
        <ValidationMessage For="@(() => user.Username)" />
    </div>

    <div>
        <label>Password:</label>
        <PasswordStrength
            @bind-Value="user.Password"
            class="form-control"
            Placeholder="Please enter your password"
            OnValidation="HandleOnValidation"
            StrengthOptions="@StrengthOptions"
            ErrorMessage="Password strength failed"
        />
        <ValidationMessage For="@(() => user.Password)" />
        <span style=@($"font-size:12px; color:{(isError == null? "black" : (isError == true ? "red" : "green" ))}")>
            Password must have
            <ul>
                <li>at least 9 chars</li>
                <li>at least 2 uppercase</li>
                <li>at least 3 lowercase</li>
                <li>at least 2 digit</li>
                <li>at least 2 special char</li>
                <li>no more than 2 same consecutive chars</li>
                <li>no more than 3 consecutive ascending digits</li>
                <li>no more than 2 consecutive descending digits</li>
                <li>no more than 3 consecutive ascending chars</li>
                <li>no more than 2 consecutive descending chars</li>
                <li>no repeating sequence 2 or more chars long</li>
            </ul>
        </span>        
    </div>

    <button type="submit" class="btn btn-primary">Register</button>
</EditForm>

@code {
    private UserModel user = new();
    private bool? isError = null;

    private MyPasswordStrengthOptions StrengthOptions
    {
        get
        {
            return new MyPasswordStrengthOptions
            {
                MinimumLength = 9,
                RequireUppercase = true,
                MinimumUppercase = 2,
                RequireLowercase = true,
                MinimumLowercase = 3,
                RequireDigit = true,
                MinimumDigit = 2,
                RequireSpecialCharacter = true,
                MinimumSpecialCharacter = 2,
                RequireMaximumNoOfSameConsecutiveCharacters = true,
                MaximumNoOfSameConsecutiveCharacters = 2,
                RequireMaximumNoOfConsecutiveAscendingDigits = true,
                MaximumNoOfConsecutiveAscendingDigits = MaximumNoOfConsecutiveDigits.Three,
                RequireMaximumNoOfConsecutiveDescendingDigits = true,
                MaximumNoOfConsecutiveDescendingDigits = MaximumNoOfConsecutiveDigits.Two,
                RequireMaximumNoOfConsecutiveAscendingCharacters = true,
                MaximumNoOfConsecutiveAscendingCharacters = MaximumNoOfConsecutiveCharacters.Three,
                RequireMaximumNoOfConsecutiveDescendingCharacters = true,
                MaximumNoOfConsecutiveDescendingCharacters = MaximumNoOfConsecutiveCharacters.Two,
                RequireRepeatingSequenceCheck = true,
                MinimumLengthOfRepeatingSequence = 2
            };
        }
    }

    private void HandleOnValidation(string? pwd, bool? isValid)
    {
        //Console.WriteLine($"Password: {pwd}, IsValid: {isValid}");

        isError = !isValid;

        StateHasChanged();
    }

    private void HandleValidSubmit()
    {
        // Handle registration logic here
        //Console.WriteLine($"Username: {user.Username}, Password: {user.Password}");
    }
}

Data Annotation

The data annotation hooks into Blazor's form validation system and provides real-time feedback on password strength as the user types.

Just decorate your model's password property with the annotation.

Sample Usage

The User model

using MyPasswordStrength.Blazor;
using System.ComponentModel.DataAnnotations;

namespace YourNamespace.Models
{
    public class UserModel
    {
        [Required(ErrorMessage = "Username is required")]
        public string Username { get; set; } = string.Empty;

        [Required(ErrorMessage = "Password is required")]
        [PasswordStrength(minimumLength: 9,
                    minUppercase: 2,
                    minLowercase: 3,
                    minDigit: 2,
                    minSpecialCharacter: 2,
                    maxNoOfSameConsecutiveCharacters: 2,
                    maxNoOfConsecutiveAscendingDigits: MaximumNoOfConsecutiveDigits.Three,
                    maxNoOfConsecutiveDescendingDigits: MaximumNoOfConsecutiveDigits.Two,
                    maxNoOfConsecutiveAscendingCharacters: MaximumNoOfConsecutiveCharacters.Three,
                    maxNoOfConsecutiveDescendingCharacters: MaximumNoOfConsecutiveCharacters.Two,
                    minLengthOfRepeatingSequence: 2,
                    ErrorMessage = "Invalid password strength")]
        public string Password { get; set; } = string.Empty;
    }
}

Multilingual feature

The library supports below languages.

  • English (default)
  • Bangla
  • Hindi
  • Punjabi
  • Chinese
  • Korean
  • Japanese
  • Urdu
  • Arabic
  • Hebrew

You can set a property of the MyPasswordStrengthOptions options called Language.

You can set the language constructor parameter of the PasswordStrengthAttribute attribute.

For languages other than English, properties RequireLowercase & MinLowercase do not apply.

License

MIT © VeritasSoftware

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 48 7/13/2026

Initial release.