Class PasswordHelper
Provides utility methods for handling password hashing and validation.
Inherited Members
Namespace: Innovt.Core.Utilities
Assembly: Innovt.Core.dll
Syntax
public static class PasswordHelper
Methods
| Edit this page View SourceGeneratePassword(int)
Generates a random password of specified length using cryptographic randomness to ensure security.
Declaration
public static string GeneratePassword(int passwordLength)
Parameters
Type | Name | Description |
---|---|---|
int | passwordLength | (int): The desired length of the generated password. If the specified length is less than 6, the method defaults to a minimum length of 6 to ensure a reasonable level of security. |
Returns
Type | Description |
---|---|
string | (string) A randomly generated password consisting of characters chosen from a predefined set. |
HashPassword(string)
Hashes a plain text password using a randomly generated salt and returns both the hashed password and the salt.
Declaration
public static (string password, string salt) HashPassword(string plainPassword)
Parameters
Type | Name | Description |
---|---|---|
string | plainPassword | The plain text password to hash. |
Returns
Type | Description |
---|---|
(string bucket, string fileKey) | A tuple containing the hashed password and the salt used. |
HashPassword(string, string)
Hashes a plain text password using the provided salt.
Declaration
public static string HashPassword(string plainPassword, string salt)
Parameters
Type | Name | Description |
---|---|---|
string | plainPassword | The plain text password to hash. |
string | salt | The salt used for hashing the password. |
Returns
Type | Description |
---|---|
string | The hashed password as a string. |
IsValid(string, string, string)
Checks if a decoded password matches its hashed representation using the provided salt.
Declaration
public static bool IsValid(string decodedPassword, string hashedPassword, string salt)
Parameters
Type | Name | Description |
---|---|---|
string | decodedPassword | The plain text password to validate. |
string | hashedPassword | The hashed password to compare against. |
string | salt | The salt used for hashing the password. |
Returns
Type | Description |
---|---|
bool | True if the decoded password matches the hashed password; otherwise, false. |
RandomSalt()
Generates a random salt and returns it as a Base64-encoded string.
Declaration
public static string RandomSalt()
Returns
Type | Description |
---|---|
string | A Base64-encoded salt. |