Password

Introduction

To generate a password using LeoCorpLibrary, you must include this line of code in your "using" region:

C#

using LeoCorpLibrary;

VB

Imports LeoCorpLibrary

Functions

a. Generate

To generate a password, you need to call the Generate() method, in:

LeoCorpLibrary.Password.Generate()

It returns a string value. This method has two variations.

Generate(length, chars, separator)

This method is available in version 1.4 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method has a few parameters:

TypeArgumentDescriptionExample
intlengthLength of the password10
stringcharsCharacters that are used to generate the password"a,b,c,d"
stringseparatorSeparator","

Here's an example of usage:

C#

Console.WriteLine(Password.Generate(10, "a,b,c,d", ","));

VB

Console.WriteLine(Password.Generate(10, "a,b,c,d", ","))

Go to top

Generate(length, passwordPresets)

This method is available in version 2.4 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method has a few parameters:

TypeArgumentDescriptionExample
intlengthLength of the password10
PasswordPresetspasswordPresetsThe preset used for the password generationPasswordPresets.Simple

Here's an example of usage:

C#

Console.WriteLine(Password.Generate(10, PasswordPresets.Simple));

VB

Console.WriteLine(Password.Generate(10, PasswordPresets.Simple))

Go to top

b. GenerateAsync

To generate a password, you need to call the GenerateAsync() method, in:

LeoCorpLibrary.Password.GenerateAsync()

It returns a Task<string> value. This method has two variations.

GenerateAsync(length, chars, separator)

This method is available in version 2.4 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method has a few parameters:

TypeParameterDescriptionExample
intlengthLength of the password10
stringcharsCharacters that are used to generate the password"a,b,c,d"
stringseparatorSeparator","

Here's an example of usage:

C#

Console.WriteLine(await Password.GenerateAsync(10, "a,b,c,d", ","));

VB

Console.WriteLine(Await Password.GenerateAsync(10, "a,b,c,d", ","))

Go to top

GenerateAsync(length, passwordPresets)

This method is available in version 2.4 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method has a few parameters:

TypeParameterDescriptionExample
intlengthLength of the password10
PasswordPresetspasswordPresetsThe preset used for the password generationPasswordPresets.Simple

Here's an example of usage:

C#

Console.WriteLine(await Password.GenerateAsync(10, PasswordPresets.Simple));

VB

Console.WriteLine(Await Password.GenerateAsync(10, PasswordPresets.Simple))

Go to top

c. GenerateAmount

To generate multiple passwords you need to call this method, in.

LeoCorpLibrary.Password.GenerateAmount()

It returns a List<string> value. This method has two variations.

GenerateAmount(amount, length, chars, separator)

This method is available in version 3.7 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method has a few parameters:

TypeArgumentDescriptionExample
intamountNumber of passwords to generate20
intlengthLength of the password10
stringcharsCharacters that are used to generate the password"a,b,c,d"
stringseparatorSeparator","

Here's an example of usage:

C#

List<string> passwords = Password.GenerateAmount(20, 10, "a,b,c,d", ",");

for (int i = 0; i < passwords.Count; i++) // For each password
{
    Console.WriteLine(passwords[i]); // Print password in console
}

VB

Dim passwords As List(Of String) = Password.GenerateAmount(20, 10, "a,b,c,d", ",")

For i As Integer = 0 To passwords.Count - 1 ' For each password
    Console.WriteLine(passwords(i)) ' Print password in console
Next

Go to top

GenerateAmount(amount, length, passwordPresets)

This method is available in version 3.7 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method has a few parameters:

TypeArgumentDescriptionExample
intamountNumber of passwords to generate20
intlengthLength of the password10
PasswordPresetspasswordPresetsThe preset used for the password generationPasswordPresets.Simple

Here's an example of usage:

C#

List<string> passwords = Password.GenerateAmount(20, 10, PasswordPresets.Complex);

for (int i = 0; i < passwords.Count; i++) // For each password
{
    Console.WriteLine(passwords[i]); // Print password in console
}

VB

Dim passwords As List(Of String) = Password.GenerateAmount(20, 10, PasswordPresets.Complex)

For i As Integer = 0 To passwords.Count - 1 ' For each password
    Console.WriteLine(passwords(i)) ' Print password in console
Next

Go to top

d. GenerateAmountAsync

To generate multiple passwords asynchronously you need to call this method, in.

LeoCorpLibrary.Password.GenerateAmountAsync()

It returns a Task<List<string>> value. This method has two variations.

GenerateAmountAsync(amount, length, chars, separator)

This method is available in version 3.7 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method has a few parameters:

TypeParameterDescriptionExample
intamountNumber of passwords to generate20
intlengthLength of the password10
stringcharsCharacters that are used to generate the password"a,b,c,d"
stringseparatorSeparator","

Here's an example of usage:

C#

List<string> passwords = await Password.GenerateAmountAsync(20, 10, "a,b,c,d", ",");

for (int i = 0; i < passwords.Count; i++) // For each password
{
    Console.WriteLine(passwords[i]); // Print password in console
}

VB

Dim passwords As List(Of String) = Await Password.GenerateAmountAsync(20, 10, "a,b,c,d", ",")

For i As Integer = 0 To passwords.Count - 1 ' For each password
     Console.WriteLine(passwords(i)) ' Print password in console
Next

Go to top

GenerateAmountAsync(amount, length, passwordPresets)

This method is available in version 3.7 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method has a few parameters:

TypeParameterDescriptionExample
intamountNumber of passwords to generate20
intlengthLength of the password10
PasswordPresetspasswordPresetsThe preset used for the password generationPasswordPresets.Simple

Here's an example of usage:

C#

List<string> passwords = await Password.GenerateAmountAsync(20, 10, PasswordPresets.Complex);

for (int i = 0; i < passwords.Count; i++) // For each password
{
    Console.WriteLine(passwords[i]); // Print password in console
}

VB

Dim passwords As List(Of String) = Await Password.GenerateAmountAsync(20, 10, PasswordPresets.Complex)

For i As Integer = 0 To passwords.Count - 1 ' For each password
    Console.WriteLine(passwords(i)) ' Print password in console
Next

Go to top

e. GetPasswordStrength

This method is available in version 3.8 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The GetPasswordStrength() method allows you to evaluate a password's strength using Passlissopen in new window' standards. It returns a PasswordStrength enum.

It's in:

LeoCorpLibrary.Password.GetPasswordStrength() {...}

It has one argument:

TypeArgumentDescriptionExample
stringpasswordThe password to test"Ftel_UGbn542"

Here's an example of usage:

C#

string[] passwords =
{
	"Ifhi2ztbg1",
	"pars132",
	"Lo8_n0D",
	"uifVyuiVVH_çVIvc",
	"gygYUI4"
};
		
List<PasswordStrength> forces = new List<PasswordStrength>();
		
for (int i = 0; i < passwords.Length; i++)
{
	forces.Add(Password.GetPasswordStrength(passwords[i]));
}

/* 
forces' content:
Medium
Low
Good
VeryGood
Medium
*/

VB

Dim passwords As String() = {"Ifhi2ztbg1", "pars132", "Lo8_n0D", "uifVyuiVVH_çVIvc", "gygYUI4"}

Dim forces As List(Of PasswordStrength) = New List(Of PasswordStrength)()

For i As Integer = 0 To passwords.Length - 1
    forces.Add(Password.GetPasswordStrength(passwords(i)))
Next
' forces' content:
' Medium
' Low
' Good
' VeryGood
' Medium

Go to top

Enumerations

a. PasswordStrength

This enumeration is available in version 3.8 and higher.

The PasswordStrength enumeration can be equal to:

  • Low
  • Medium
  • Good
  • VeryGood

Go to top