EasyPassword

EasyPassword

A .NET Standard library which help you easily work with password

Installation

https://www.nuget.org/packages/EasyPassword

Install-Package EasyPassword

API

using EasyPassword;

Methods

string Hash(string rawPassword);

Get hashed string for given string.

Parameters Hash(string rawPassword).png Return Screen Shot 2021-12-19 at 13.19.34.png Example

string hashedPassword = PasswordHelper.Hash("hihi");

string Hash(string rawPassword, byte[] salt);

Get hashed string for given string and salt.

Parameters Screen Shot 2021-12-19 at 13.29.12.png Return Screen Shot 2021-12-19 at 13.19.34.png Example

string hashedPassword = PasswordHelper.Hash("hihi", new byte[16]);

bool VerifyPassword(string rawPassword, string hashedPassword);

Validate hashed string with raw string.

Parameters Screen Shot 2021-12-19 at 13.37.10.png Return Screen Shot 2021-12-19 at 13.39.36.png Example

bool isMatch = PasswordHelper.VerifyPassword("ahihi", "Cc2aQrLTVW7V9bwTUvO+Gtm2wwjywWM1LT6GOmjzsx9f9WmU");

string GenerateRandomPassword(PasswordOptions opts = null);

Generates a Random Password with rule. If opts is null will use default value as follows { NumberMinLength = 6, NumberUniqueChars = 4, RequireDigit = true, RequireLowercase = true, RequireNonAlphanumeric = true, NumberNonAlphanumeric = 1, RequireUppercase = true };

Parameters Screen Shot 2021-12-19 at 14.06.31.png Return Screen Shot 2021-12-19 at 14.07.42.png Example

string randomPassword = PasswordHelper.GenerateRandomPassword();

PasswordOptions opts = new PasswordOptions
{
    NumberMinLength = 8,
    NumberUniqueChars = 6,
    RequireDigit = true,
    RequireLowercase = true,
    RequireNonAlphanumeric = true,
    NumberNonAlphanumeric = 3,
    RequireUppercase = true
};
string randomPasswordOpts = PasswordHelper.GenerateRandomPassword(opts);

List<string> VerifyPasswordValidRule(string password, PasswordOptions opts = null);

Check password is valid rule. If opts is null will use default value as follows { NumberMinLength = 6, NumberUniqueChars = 4, RequireDigit = true, RequireLowercase = true, RequireNonAlphanumeric = true, NumberNonAlphanumeric = 1, RequireUppercase = true };

Parameters Screen Shot 2021-12-19 at 14.22.17.png Return Screen Shot 2021-12-19 at 14.25.17.png Example

List<string> listError = PasswordHelper.VerifyPasswordValidRule("abc");

PasswordOptions opts = new PasswordOptions
{
    NumberMinLength = 8,
    NumberMinLengthMsg = "Custom message error otherwise it use default msg",
    NumberUniqueChars = 6,
    NumberUniqueCharsMsg = "Custom message error otherwise it use default msg",
    RequireDigit = true,
    RequireDigitMsg = "Custom message error otherwise it use default msg",
    RequireLowercase = true,
    RequireLowercaseMsg = "Custom message error otherwise it use default msg",
    RequireNonAlphanumeric = true,
    RequireNonAlphanumericMsg =  "Custom message error otherwise it use default msg",
    NumberNonAlphanumeric = 3,
    NumberNonAlphanumericMsg =  "Custom message error otherwise it use default msg",
    RequireUppercase = true,
    RequireUppercaseMsg = "Custom message error otherwise it use default msg"
};
List<string> listErrorOpts = PasswordHelper.VerifyPasswordValidRule("abc", opts);