HtpasswdFile Class
Represents an htpasswd file and provides methods to parse and verify credentials.
public sealed class HtpasswdFileProperties
| Name | Description |
|---|---|
| AllowPlaintextPasswords | Gets a value indicating whether entries whose format is not recognized are compared as plaintext passwords. |
| Count | Gets the number of entries in the file. |
| Usernames | Gets the list of usernames in the file. |
AllowPlaintextPasswords
HtpasswdFile.csCount
HtpasswdFile.csUsernames
HtpasswdFile.csMethods
| Name | Description |
|---|---|
| LoadAsync(TextReader) | Loads and parses an htpasswd file from a TextReader. Entries whose format is not recognized are rejected. |
| LoadAsync(TextReader, bool, CancellationToken) | Loads and parses an htpasswd file from a TextReader. |
| LoadAsync(TextReader, CancellationToken) | Loads and parses an htpasswd file from a TextReader. Entries whose format is not recognized are rejected. |
| LoadAsync(string) | Loads and parses an htpasswd file from disk. Entries whose format is not recognized are rejected. |
| LoadAsync(string, bool, CancellationToken) | Loads and parses an htpasswd file from disk. |
| LoadAsync(string, CancellationToken) | Loads and parses an htpasswd file from disk. Entries whose format is not recognized are rejected. |
| Parse(ReadOnlySpan<char>) | Parses the content of an htpasswd file. |
| Parse(ReadOnlySpan<char>, bool) | Parses the content of an htpasswd file. |
| Parse(string) | Parses the content of an htpasswd file. Entries whose format is not recognized are rejected. |
| Parse(string, bool) | Parses the content of an htpasswd file. |
| VerifyCredentials(ReadOnlySpan<char>, ReadOnlySpan<char>) | Verifies a username and password against the current htpasswd entries. |
| VerifyCredentials(string, string) | Verifies a username and password against the current htpasswd entries. |
LoadAsync overloads
LoadAsync(TextReader)
HtpasswdFile.csLoads and parses an htpasswd file from a TextReader. Entries whose format is not recognized are rejected.
public static Task<HtpasswdFile> LoadAsync(TextReader file)Parameters
fileTextReader- The reader containing the htpasswd content.
Returns
Task<HtpasswdFile> A parsed HtpasswdFile instance.
LoadAsync(TextReader, bool, CancellationToken)
HtpasswdFile.csLoads and parses an htpasswd file from a TextReader.
net10.0
public static Task<HtpasswdFile> LoadAsync(TextReader file, bool allowPlaintextPasswords, CancellationToken cancellationToken = default)net11.0
public static Task<HtpasswdFile> LoadAsync(TextReader file, bool allowPlaintextPasswords, CancellationToken cancellationToken = default)Parameters
fileTextReader- The reader containing the htpasswd content.
allowPlaintextPasswordsbooltrueto compare an entry whose format is not recognized against the password as plaintext;falseto reject it.cancellationTokenCancellationToken- A token to cancel the operation.
Returns
Task<HtpasswdFile> A parsed HtpasswdFile instance.
LoadAsync(TextReader, CancellationToken)
HtpasswdFile.csLoads and parses an htpasswd file from a TextReader. Entries whose format is not recognized are rejected.
public static Task<HtpasswdFile> LoadAsync(TextReader file, CancellationToken cancellationToken)Parameters
fileTextReader- The reader containing the htpasswd content.
cancellationTokenCancellationToken- A token to cancel the operation.
Returns
Task<HtpasswdFile> A parsed HtpasswdFile instance.
LoadAsync(string)
HtpasswdFile.csLoads and parses an htpasswd file from disk. Entries whose format is not recognized are rejected.
public static Task<HtpasswdFile> LoadAsync(string file)Parameters
filestring- The path of the htpasswd file.
Returns
Task<HtpasswdFile> A parsed HtpasswdFile instance.
LoadAsync(string, bool, CancellationToken)
HtpasswdFile.csLoads and parses an htpasswd file from disk.
net10.0
public static Task<HtpasswdFile> LoadAsync(string file, bool allowPlaintextPasswords, CancellationToken cancellationToken = default)net11.0
public static Task<HtpasswdFile> LoadAsync(string file, bool allowPlaintextPasswords, CancellationToken cancellationToken = default)Parameters
filestring- The path of the htpasswd file.
allowPlaintextPasswordsbooltrueto compare an entry whose format is not recognized against the password as plaintext;falseto reject it. Enabling this also accepts hashes the library does not implement, such as traditional DES crypt, as plaintext passwords.cancellationTokenCancellationToken- A token to cancel the operation.
Returns
Task<HtpasswdFile> A parsed HtpasswdFile instance.
LoadAsync(string, CancellationToken)
HtpasswdFile.csLoads and parses an htpasswd file from disk. Entries whose format is not recognized are rejected.
public static Task<HtpasswdFile> LoadAsync(string file, CancellationToken cancellationToken)Parameters
filestring- The path of the htpasswd file.
cancellationTokenCancellationToken- A token to cancel the operation.
Returns
Task<HtpasswdFile> A parsed HtpasswdFile instance.
Parse overloads
Parse(ReadOnlySpan<char>)
HtpasswdFile.csParses the content of an htpasswd file.
public static HtpasswdFile Parse(ReadOnlySpan<char> content)Parameters
contentReadOnlySpan<char>- The text content of the htpasswd file.
Returns
HtpasswdFile A parsed HtpasswdFile instance.
Parse(ReadOnlySpan<char>, bool)
HtpasswdFile.csParses the content of an htpasswd file.
public static HtpasswdFile Parse(ReadOnlySpan<char> content, bool allowPlaintextPasswords)Parameters
contentReadOnlySpan<char>- The text content of the htpasswd file.
allowPlaintextPasswordsbooltrueto compare an entry whose format is not recognized against the password as plaintext;falseto reject it.
Returns
HtpasswdFile A parsed HtpasswdFile instance.
Parse(string)
HtpasswdFile.csParses the content of an htpasswd file. Entries whose format is not recognized are rejected.
public static HtpasswdFile Parse(string content)Parameters
contentstring- The text content of the htpasswd file.
Returns
HtpasswdFile A parsed HtpasswdFile instance.
Parse(string, bool)
HtpasswdFile.csParses the content of an htpasswd file.
public static HtpasswdFile Parse(string content, bool allowPlaintextPasswords)Parameters
contentstring- The text content of the htpasswd file.
allowPlaintextPasswordsbooltrueto compare an entry whose format is not recognized against the password as plaintext;falseto reject it. Enabling this also accepts hashes the library does not implement, such as traditional DES crypt, as plaintext passwords.
Returns
HtpasswdFile A parsed HtpasswdFile instance.
VerifyCredentials overloads
VerifyCredentials(ReadOnlySpan<char>, ReadOnlySpan<char>)
HtpasswdFile.csVerifies a username and password against the current htpasswd entries.
public bool VerifyCredentials(ReadOnlySpan<char> username, ReadOnlySpan<char> password)Parameters
usernameReadOnlySpan<char>- The username to verify.
passwordReadOnlySpan<char>- The plaintext password to verify. A password longer than 1024 characters is always rejected.
Returns
bool true if the credentials are valid; otherwise, false.
VerifyCredentials(string, string)
HtpasswdFile.csVerifies a username and password against the current htpasswd entries.