MyPasswordStrength.NET.MAUI
3.0.0
dotnet add package MyPasswordStrength.NET.MAUI --version 3.0.0
NuGet\Install-Package MyPasswordStrength.NET.MAUI -Version 3.0.0
<PackageReference Include="MyPasswordStrength.NET.MAUI" Version="3.0.0" />
<PackageVersion Include="MyPasswordStrength.NET.MAUI" Version="3.0.0" />
<PackageReference Include="MyPasswordStrength.NET.MAUI" />
paket add MyPasswordStrength.NET.MAUI --version 3.0.0
#r "nuget: MyPasswordStrength.NET.MAUI, 3.0.0"
#:package MyPasswordStrength.NET.MAUI@3.0.0
#addin nuget:?package=MyPasswordStrength.NET.MAUI&version=3.0.0
#tool nuget:?package=MyPasswordStrength.NET.MAUI&version=3.0.0
MyPasswordStrength.NET.MAUI
A .NET MAUI 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 PasswordStrengthEntry Entry and a PasswordStrengthAttribute that you can use to validate passwords in your .NET MAUI applications.
Entry
You can set the password strength requirements through the properties of the MyPasswordStrengthOptions class and pass the options to the Entry.
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
XAML page
RegistrationPage.xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pwd="clr-namespace:MyPasswordStrength.NET.MAUI;assembly=MyPasswordStrength.NET.MAUI"
x:Class="YourNamespace.Pages.RegistrationPage"
Title="Registration"
x:Name="registrationPage">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Border x:Name="border" Stroke="Black" StrokeThickness="2">
<pwd:PasswordStrengthEntry
x:Name="passwordStrength"
Placeholder="Please enter password" />
</Border>
<Label
x:Name="errorLabel"
Text="Password must be at least 9 chars, 2 uppercase, 3 lowercase, 2 digit, 2 special char, no more than 2 same consecutive chars, no more than 3 consecutive ascending digits, no more than 2 consecutive descending digits, no more than 3 consecutive ascending chars, no more than 2 consecutive descending chars and no repeating sequence 2 or more chars long"
FontSize="24"
IsVisible="False"
TextColor="Red"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentPage>
RegistrationPage.xaml.cs:
using MyPasswordStrength.NET.MAUI;
namespace YourNamespace.Pages;
public partial class RegistrationPage : ContentPage
{
public RegistrationPage()
{
InitializeComponent();
passwordStrength.StrengthOptions = StrengthOptions;
passwordStrength.OnValidation = HandleOnValidation;
}
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 async void HandleOnValidation(string pwd, bool isValid)
{
if (isValid)
{
border.Stroke = Colors.Green;
errorLabel.IsVisible = false;
}
else
{
border.Stroke = Colors.Red;
errorLabel.IsVisible = true;
}
}
}
Code only page
Registration.cs:
using Microsoft.Maui.Controls.Shapes;
using MyPasswordStrength.NET.MAUI;
using System.Runtime.Versioning;
namespace YourNamespace.Pages;
[SupportedOSPlatform("android")]
[SupportedOSPlatform("ios")]
[SupportedOSPlatform("maccatalyst")]
[SupportedOSPlatform("windows")]
public class Registration : ContentPage
{
private readonly PasswordStrengthEntry _entry;
private readonly Border _border;
private readonly Label _errorLabel;
public Registration()
{
var content = new VerticalStackLayout
{
Children = {
new Label {
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Text = "Welcome to .NET MAUI!"
}
}
};
_entry = new PasswordStrengthEntry(HandleOnValidation, StrengthOptions, "Enter your password")
{
HorizontalOptions = LayoutOptions.Fill,
VerticalOptions = LayoutOptions.Fill
};
_border = new Border
{
Stroke = Colors.Black, // Border color
StrokeThickness = 1, // Border width in device-independent units
StrokeShape = new Rectangle(), //Square border
Margin = 10,
Content = _entry
};
_errorLabel = new Label
{
Text = "Password must be at least 9 chars, 2 uppercase, 3 lowercase, 2 digit, 2 special char, no more than 2 same consecutive chars, no more than 3 consecutive ascending digits, no more than 2 consecutive descending digits, no more than 3 consecutive ascending chars, no more than 2 consecutive descending chars and no repeating sequence 2 or more chars long",
TextColor = Colors.Red,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
IsVisible = false
};
content.Children.Add(_border);
content.Children.Add(_errorLabel);
Content = content;
}
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 async void HandleOnValidation(string pwd, bool isValid)
{
if (isValid)
{
_border.Stroke = Colors.Green;
_errorLabel.IsVisible = false;
}
else
{
_border.Stroke = Colors.Red;
_errorLabel.IsVisible = true;
}
}
}
Data Annotation
The data annotation hooks into .NET MAUI'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.NET.MAUI;
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-android36.0 is compatible. net10.0-browser was computed. net10.0-ios was computed. net10.0-ios26.0 is compatible. net10.0-maccatalyst was computed. net10.0-maccatalyst26.0 is compatible. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net10.0-windows10.0.19041 is compatible. |
-
net10.0
- Microsoft.Maui.Controls (>= 10.0.20)
-
net10.0-android36.0
- Microsoft.Maui.Controls (>= 10.0.20)
-
net10.0-ios26.0
- Microsoft.Maui.Controls (>= 10.0.20)
-
net10.0-maccatalyst26.0
- Microsoft.Maui.Controls (>= 10.0.20)
-
net10.0-windows10.0.19041
- Microsoft.Maui.Controls (>= 10.0.20)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added multilingual feature. added data annotation.