securePasswordType 1.0.1

dotnet add package securePasswordType --version 1.0.1
                    
NuGet\Install-Package securePasswordType -Version 1.0.1
                    
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="securePasswordType" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="securePasswordType" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="securePasswordType" />
                    
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 securePasswordType --version 1.0.1
                    
#r "nuget: securePasswordType, 1.0.1"
                    
#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 securePasswordType@1.0.1
                    
#: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=securePasswordType&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=securePasswordType&version=1.0.1
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
1.0.1 236 2/22/2024
1.0.0 197 2/21/2024