Class PasswordRule
- Namespace
- AetherUtils.Core.Security.Passwords
- Assembly
- AetherUtils.Core.dll
Represents a password rule with various options. A password rule should be built using the
Rule Builder factory: IPasswordRuleBuilder.
A password can be validated against a rule using Validate(string).
This class contains methods to parse and save a password rule to/from a file as well as a string.
public sealed class PasswordRule
- Inheritance
-
PasswordRule
- Inherited Members
- Extension Methods
Properties
PasswordRules
Get the string representing this password rule.
public string PasswordRules { get; }
Property Value
Methods
FromEncryptedString(string, string)
Parse a password rule from an encrypted string.
public static PasswordRule FromEncryptedString(string encrypted, string passphrase)
Parameters
encryptedstring- The encrypted password rule to parse.
passphrasestring- The passphrase used for decryption.
Returns
- PasswordRule
- The PasswordRule or
nullif parsing failed.
GetValidPassword()
Get a random, cryptographically strong password that follows the password rule.
public string GetValidPassword()
Returns
- string
- A new, random password that adheres to the password rule created.
New()
Start building the password rule.
public static IPasswordRuleBuilder New()
Returns
- IPasswordRuleBuilder
- The builder instance.
Parse(string)
Parse a password rule from a Json string.
public static PasswordRule Parse(string json)
Parameters
jsonstring- The password rule as Json to parse.
Returns
- PasswordRule
- The PasswordRule or
nullif parsing failed.
ParseFromFileAsync(string, string)
Parse an encrypted password rule from a file.
public static Task<PasswordRule?> ParseFromFileAsync(string filePath, string passphrase)
Parameters
filePathstring- The path to the file to load; can contain Windows path variables (i.e.,
%temp%) passphrasestring- The passphrase used for decryption. Should be the same as the one used for encryption.
Returns
- Task<PasswordRule>
- The PasswordRule or
nullif parsing failed.
SaveToFileAsync(string, string)
Save the encrypted password rule to a file.
public Task<bool> SaveToFileAsync(string filePath, string passphrase)
Parameters
filePathstring- The path to the file to save; can contain Windows path variables (i.e.,
%temp%) passphrasestring- The passphrase used for encryption.
Returns
ToEncryptedString(string)
Get an encrypted string representing this password rule.
public string ToEncryptedString(string passphrase)
Parameters
passphrasestring- The passphrase used for encryption.
Returns
- string
- A base64 string representing the password rule.
ToString()
Get the Json string representing this password rule.
public override string ToString()
Returns
Validate(string)
Validate a password against this rule.
public List<IValidationFailure> Validate(string password)
Parameters
passwordstring- The password to validate.
Returns
- List<IValidationFailure>
- A list of IValidationFailure containing the reasons the password failed to validate. If this list is empty, the password validated successfully.