Class PasswordStorage
Contains methods for creating Salty Hashes of passwords that are safe to store, as well as verifying a password’s validity.
Inherited Members
Namespace: TheXDS.MCART.Helpers
Assembly: MCART.Security.dll
Syntax
public static class PasswordStorage
Methods
| Edit this page View SourceCreateHash(IPasswordStorage, SecureString)
Creates a secure hash for storing a password.
Declaration
public static byte[] CreateHash(IPasswordStorage algorithm, SecureString password)
Parameters
| Type | Name | Description |
|---|---|---|
| IPasswordStorage | algorithm | Key‑derivation algorithm to use. |
| SecureString | password | Password to store. |
Returns
| Type | Description |
|---|---|
| byte[] | A byte array that can be safely stored in a database and later used to verify a password. The array includes information about the derivation algorithm used, as well as all of its configuration parameters. |
CreateHash<T>(SecureString)
Creates a secure hash for storing a password.
Declaration
public static byte[] CreateHash<T>(SecureString password) where T : IPasswordStorage, new()
Parameters
| Type | Name | Description |
|---|---|---|
| SecureString | password | Password to store. |
Returns
| Type | Description |
|---|---|
| byte[] | A byte array that can be safely stored in a database and later used to verify a password. |
Type Parameters
| Name | Description |
|---|---|
| T | Key‑derivation algorithm to use. |
RegisterAlgorithm(IPasswordStorage)
Registers an algorithm instance to provide password hashing and verification services.
Declaration
public static void RegisterAlgorithm(IPasswordStorage alg)
Parameters
| Type | Name | Description |
|---|---|---|
| IPasswordStorage | alg | Algorithm instance to register. |
RegisterAlgorithm<T>()
Registers an algorithm to provide password hashing and verification services.
Declaration
public static void RegisterAlgorithm<T>() where T : IPasswordStorage, new()
Type Parameters
| Name | Description |
|---|---|
| T | Type of algorithm to be registered. It must have a public parameterless constructor. |
VerifyPassword(SecureString, byte[])
Verifies a password.
Declaration
public static bool? VerifyPassword(SecureString password, byte[] hash)
Parameters
| Type | Name | Description |
|---|---|---|
| SecureString | password | Password to verify. |
| byte[] | hash | Hash to compare against. It must contain information about the key‑derivation algorithm used, as well as any required configuration values. |
Returns
| Type | Description |
|---|---|
| bool? | true if the password is valid, false otherwise, or null if an error occurs during verification (e.g., due to tampering). |