MyPasswordStrength.NET.MAUI
2.0.1
dotnet add package MyPasswordStrength.NET.MAUI --version 2.0.1
NuGet\Install-Package MyPasswordStrength.NET.MAUI -Version 2.0.1
<PackageReference Include="MyPasswordStrength.NET.MAUI" Version="2.0.1" />
<PackageVersion Include="MyPasswordStrength.NET.MAUI" Version="2.0.1" />
<PackageReference Include="MyPasswordStrength.NET.MAUI" />
paket add MyPasswordStrength.NET.MAUI --version 2.0.1
#r "nuget: MyPasswordStrength.NET.MAUI, 2.0.1"
#:package MyPasswordStrength.NET.MAUI@2.0.1
#addin nuget:?package=MyPasswordStrength.NET.MAUI&version=2.0.1
#tool nuget:?package=MyPasswordStrength.NET.MAUI&version=2.0.1
MyPasswordStrength.NET.MAUI
A .NET MAUI library for validating password strength based on customizable complexity requirements.
You can configure:
- 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
Background
Define your password strength complexity requirements with ease using the library.
The package provides a PasswordStrengthEntry Entry that you can use to validate passwords in your .NET MAUI applications.
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;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"
FontSize="24"
IsVisible="False"
TextColor="Red"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentPage>
RegistrationPage.xaml.cs:
using MyPasswordStrength;
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
};
}
}
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;
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",
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
};
}
}
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;
}
}
}
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 features to validate max no of consecutive ascending and/or descending characters.