SecureTokenGeneratR 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SecureTokenGeneratR --version 1.0.0
NuGet\Install-Package SecureTokenGeneratR -Version 1.0.0
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="SecureTokenGeneratR" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SecureTokenGeneratR --version 1.0.0
#r "nuget: SecureTokenGeneratR, 1.0.0"
#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 SecureTokenGeneratR as a Cake Addin
#addin nuget:?package=SecureTokenGeneratR&version=1.0.0

// Install SecureTokenGeneratR as a Cake Tool
#tool nuget:?package=SecureTokenGeneratR&version=1.0.0

Secure Token Generator

Main Build

Generate random passwords or token; use the default generation rules or set your own.
Using System.Security.Cryptography.RandomNumberGenerator to generate cryptographically strong random values.

  • Dependencies: none
  • Compatibility: NET Framework 4.6.1+, Net Standard 2.0+

Default Characters Sets

  • All numbers
  • All lower case latin
  • All upper case latin
  • Special characters: !"#$%&'()*+,-./:;<=>?@[]^_`{|}~

Default Rules

  • Length: 16 characters
  • Max repeating characters: 0 (unlimited)

Generator Algorithm

  1. Populate random positions of the token with at least one random character from each character set.
  2. Populate all unfilled positions in a random order, each using a random character from a randomly selected characters set.
  3. Honour the max repeating characters constraint, replace any repeated character exceeding the constraint threshold, each using a random character from a randomly selected characters set.

Installing SecureTokenGeneratR

Install SecureTokenGeneratR with NuGet:

Install-Package SecureTokenGeneratR

Or the .Net Core CLI

dotnet add package SecureTokenGeneratR

Usage

With Default Options

var secureTokenGenerator = new SecureTokenGenerator();
string secureToken = secureTokenGenerator.Generate();

The token generated using the default options will contain 16 characters, with at least one character from each character set (i.e. lower latin, upper latin, number & special character) without limiting the number of occurrence of any character.

Note: while improbable, a random sequence such as 1111111111111111 is not impossible.

With User Defined Options

// Define custom options
var customCharset1 = new CharsetAsSequence("%XW-[]{}"); // Custom characters sets can be provided as string
var customCharset2 = new CharsetAsUnicodeRange(65, 70); // Or as a unicode range, here ABCDEF
var allowedCharsets = new List<ICharacterSet> { customCharset1, customCharset2 };

const int tokenLength = 8;
const int maxRepeatingCharCount = 2; // at most two instances of any characters from all character sets 

var secureTokenGenerator = new SecureTokenGenerator(tokenLength, maxRepeatingCharCount, allowedCharsets);
string secureToken = secureTokenGenerator.Generate();

The token generated in the example above will contain 8 characters, at least one character from each characters set and at most two occurrences of any character from all characters sets.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6.1

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • 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 1,780 10/17/2021
1.0.0 487 10/10/2021