securePasswordType 1.0.1
dotnet add package securePasswordType --version 1.0.1
NuGet\Install-Package securePasswordType -Version 1.0.1
<PackageReference Include="securePasswordType" Version="1.0.1" />
<PackageVersion Include="securePasswordType" Version="1.0.1" />
<PackageReference Include="securePasswordType" />
paket add securePasswordType --version 1.0.1
#r "nuget: securePasswordType, 1.0.1"
#:package securePasswordType@1.0.1
#addin nuget:?package=securePasswordType&version=1.0.1
#tool nuget:?package=securePasswordType&version=1.0.1
Usage
The Password class in the securePasswordType library is designed to help enforce strong password policies by validating passwords against several security criteria. This document outlines how to use the Password class to validate passwords in your C# applications.
Validating a Password
Call the Create Method: Use the Create method to attempt to create a Password object. The method checks if the input meets the security criteria and returns a Password object if it does. If the input does not meet the criteria, an ArgumentException is thrown.
Example:
using System;
using securePasswordType;
class Program
{
static void Main(string[] args)
{
try
{
var password = Password.Create("ValidPassword123!");
Console.WriteLine("Password is valid and has been successfully created.");
}
catch (ArgumentException ex)
{
Console.WriteLine($"Invalid password: {ex.Message}");
}
}
}
Security Criteria Enforced
Minimum Length: The password must be at least 12 characters long. Character Diversity: It must include at least:
- One uppercase letter (A-Z)
- One lowercase letter (a-z)
- One digit (0-9)
- One special character (e.g., !, @, #, $, etc.) No illegal characters such as white-spaces, backslashes, single or double quotes
Example Usage
The following is an example of how to prompt a user for a password and validate it using the Password class:
Console.Write("Enter a password: ");
string userInput = Console.ReadLine();
try
{
var password = Password.Create(userInput);
Console.WriteLine("Password is valid.");
}
catch (ArgumentException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Extension
The IsValid function is called to match characters. Separate functions can be added to handle each specific case or check for passwords that are too common.
private static bool IsValid(string password)
{
// Check for minimum length of 8 characters and at least one alphanumeric character
return (Your conditions here)
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.