Utilities.PasswordGenerator 6.0.910

dotnet add package Utilities.PasswordGenerator --version 6.0.910                
NuGet\Install-Package Utilities.PasswordGenerator -Version 6.0.910                
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="Utilities.PasswordGenerator" Version="6.0.910" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Utilities.PasswordGenerator --version 6.0.910                
#r "nuget: Utilities.PasswordGenerator, 6.0.910"                
#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.
// Install Utilities.PasswordGenerator as a Cake Addin
#addin nuget:?package=Utilities.PasswordGenerator&version=6.0.910

// Install Utilities.PasswordGenerator as a Cake Tool
#tool nuget:?package=Utilities.PasswordGenerator&version=6.0.910                

Utilities.PasswordGenerator

GitHub Build Status Nuget

Coverage Quality Gate Status Reliability Rating Security Rating Vulnerabilities

Ambiguous avoid, generated password will not contain 0 O 1 I l

Installation

dotnet add package Utilities.PasswordGenerator

Using service

Simple usage

using Utilities.PasswordGenerator.Services;

public class MyProcess
{
	public string Generate()
	{
		var passwordGeneratorService = new PasswordGeneratorService();

		// generate 8 characters password with at least 1 uppercase, 1 lowercase, 1 numeric and 1 special character
		return passwordGeneratorService.Generate();
	}
}

Generate with specific length

You can generate 8~32 characters password by specifying the length. (default: 8)

using Utilities.PasswordGenerator.Services;

public class MyProcess
{
	public string Generate()
	{
		var passwordGeneratorService = new PasswordGeneratorService();

		// generate 16 characters password with at least 1 uppercase, 1 lowercase, 1 numeric and 1 special character
		return passwordGeneratorService.Generate(16);
	}
}

Generate with required characters options

You can generate 8~32 characters password with specific options, i.e. at least 3 uppercase, 3 lowercase, 2 numeric and 1 special character.

using Utilities.PasswordGenerator.Services;

public class MyProcess
{
	public string Generate()
	{
		var passwordGeneratorService = new PasswordGeneratorService();

		// generate 16 characters password with at least 3 uppercase, 3 lowercase, 2 numeric and 1 special character
		return passwordGeneratorService.Generate(16, 3, 3, 2, 1);
	}
}

Custom special characters

Default special characters are ! @ # $ % ^ * ( ) - _ = + ?. You can setup your own special characters by giving specialChars parameter.

using Utilities.PasswordGenerator.Services;

public class MyProcess
{
	public string Generate()
	{
		var passwordGeneratorService = new PasswordGeneratorService();

		// generate 16 characters password with at least 1 uppercase, 1 lowercase, 1 numeric and 1 special character (~!@#<>)
		return passwordGeneratorService.Generate(16, specialChars: "~!@#<>");
	}
}

In case you don't want any special characters, you can set specialChars to empty string or null.

using Utilities.PasswordGenerator.Services;

public class MyProcess
{
	public string Generate()
	{
		var passwordGeneratorService = new PasswordGeneratorService();

		// generate 16 characters password with at least 1 uppercase, 1 lowercase, 1 numeric and no special character
		return passwordGeneratorService.Generate(16, specialChars: null);
	}
}

Password hashing

Password hashing function uses the PBKDF2 (Password-Based Key Derivation Function 2) algorithm to generate secure password hash, includes two key parameters:

  • _keySize: 128 Generates a random salt value byte array using the RandomNumberGenerator.GetBytes method. With _keySize set to 128, this means the generated salt value will have 128 bytes (256 characters).

  • _iterations: 12_800

These parameters control the output size of the hash calculation and the computational strength, thereby enhancing the security of passwords. This provides a robust password hashing solution suitable for applications requiring high security.

Hashed password will return in HashedPasswordModel object which contains Hash and Salt, you should store both values for later password verification.

Generate password hash

using Utilities.PasswordGenerator.Models.Responses;
using Utilities.PasswordGenerator.Services;

public class MyProcess
{
	public HashedPasswordModel GenerateHashed()
	{
		var passwordGeneratorService = new PasswordGeneratorService();

		// generate hash of 16 characters password with at least 1 uppercase, 1 lowercase, 1 numeric and 1 special character
		return passwordGeneratorService.GenerateHashed(16);
	}
}

Verify password

using Utilities.PasswordGenerator.Models.Requests;
using Utilities.PasswordGenerator.Services;

public class MyProcess
{
	public bool Verify()
	{
		var passwordGeneratorService = new PasswordGeneratorService();

		// prepare password, hash and salt
		var data = new VerifyPasswordModel
		{
			Password = "PLAINTEXT_PASSWORD",
			Hash = "HASH",
			Salt = "SALT"
		};

		// verify password with hash and salt
		return passwordGeneratorService.Verify(data);
	}
}

Use dependency injection

Register services

using Utilities.PasswordGenerator.Interfaces;
using Utilities.PasswordGenerator.Services;

ConfigureServices(IServiceCollection services)
{
	// this injects as SINGLETON
	services.AddSingleton<IPasswordGeneratorService, PasswordGeneratorService>();
}

Using service

using Utilities.PasswordGenerator.Interfaces;

public class MyProcess
{
	private readonly IPasswordGeneratorService _passwordGeneratorService;

	public MyProcess(IPasswordGeneratorService passwordGeneratorService) =>
		_passwordGeneratorService = _passwordGeneratorService;

	public string Generate() =>
		_passwordGeneratorService.Generate();
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.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
6.0.910 116 5/20/2024
6.0.908 90 5/19/2024
6.0.902 106 5/17/2024