Table of contents
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 Return Example
string hashedPassword = PasswordHelper.Hash("hihi");
string Hash(string rawPassword, byte[] salt);
Get hashed string for given string and salt.
Parameters Return Example
string hashedPassword = PasswordHelper.Hash("hihi", new byte[16]);
bool VerifyPassword(string rawPassword, string hashedPassword);
Validate hashed string with raw string.
Parameters Return 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 Return 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 Return 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);