HtpasswdFile Class

Represents an htpasswd file and provides methods to parse and verify credentials.

public sealed class HtpasswdFile

Properties

NameDescription
AllowPlaintextPasswordsGets a value indicating whether entries whose format is not recognized are compared as plaintext passwords.
CountGets the number of entries in the file.
UsernamesGets the list of usernames in the file.

AllowPlaintextPasswords

HtpasswdFile.cs

Gets a value indicating whether entries whose format is not recognized are compared as plaintext passwords.

public bool AllowPlaintextPasswords { get; }

Property value

bool

Gets the number of entries in the file.

public int Count { get; }

Property value

int

Gets the list of usernames in the file.

public ICollection<string> Usernames { get; }

Property value

ICollection<string>

Methods

NameDescription
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.cs

Loads and parses an htpasswd file from a TextReader. Entries whose format is not recognized are rejected.

public static Task<HtpasswdFile> LoadAsync(TextReader file)
Parameters
file TextReader
The reader containing the htpasswd content.
Returns

Task<HtpasswdFile> A parsed HtpasswdFile instance.

LoadAsync(TextReader, bool, CancellationToken)

HtpasswdFile.cs

Loads 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
file TextReader
The reader containing the htpasswd content.
allowPlaintextPasswords bool
true to compare an entry whose format is not recognized against the password as plaintext; false to reject it.
cancellationToken CancellationToken
A token to cancel the operation.
Returns

Task<HtpasswdFile> A parsed HtpasswdFile instance.

LoadAsync(TextReader, CancellationToken)

HtpasswdFile.cs

Loads 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
file TextReader
The reader containing the htpasswd content.
cancellationToken CancellationToken
A token to cancel the operation.
Returns

Task<HtpasswdFile> A parsed HtpasswdFile instance.

LoadAsync(string)

HtpasswdFile.cs

Loads and parses an htpasswd file from disk. Entries whose format is not recognized are rejected.

public static Task<HtpasswdFile> LoadAsync(string file)
Parameters
file string
The path of the htpasswd file.
Returns

Task<HtpasswdFile> A parsed HtpasswdFile instance.

LoadAsync(string, bool, CancellationToken)

HtpasswdFile.cs

Loads 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
file string
The path of the htpasswd file.
allowPlaintextPasswords bool
true to compare an entry whose format is not recognized against the password as plaintext; false to reject it. Enabling this also accepts hashes the library does not implement, such as traditional DES crypt, as plaintext passwords.
cancellationToken CancellationToken
A token to cancel the operation.
Returns

Task<HtpasswdFile> A parsed HtpasswdFile instance.

LoadAsync(string, CancellationToken)

HtpasswdFile.cs

Loads 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
file string
The path of the htpasswd file.
cancellationToken CancellationToken
A token to cancel the operation.
Returns

Task<HtpasswdFile> A parsed HtpasswdFile instance.

Parse overloads

Parse(ReadOnlySpan<char>)

HtpasswdFile.cs

Parses the content of an htpasswd file.

public static HtpasswdFile Parse(ReadOnlySpan<char> content)
Parameters
content ReadOnlySpan<char>
The text content of the htpasswd file.
Returns

HtpasswdFile A parsed HtpasswdFile instance.

Parse(ReadOnlySpan<char>, bool)

HtpasswdFile.cs

Parses the content of an htpasswd file.

public static HtpasswdFile Parse(ReadOnlySpan<char> content, bool allowPlaintextPasswords)
Parameters
content ReadOnlySpan<char>
The text content of the htpasswd file.
allowPlaintextPasswords bool
true to compare an entry whose format is not recognized against the password as plaintext; false to reject it.
Returns

HtpasswdFile A parsed HtpasswdFile instance.

Parse(string)

HtpasswdFile.cs

Parses the content of an htpasswd file. Entries whose format is not recognized are rejected.

public static HtpasswdFile Parse(string content)
Parameters
content string
The text content of the htpasswd file.
Returns

HtpasswdFile A parsed HtpasswdFile instance.

Parse(string, bool)

HtpasswdFile.cs

Parses the content of an htpasswd file.

public static HtpasswdFile Parse(string content, bool allowPlaintextPasswords)
Parameters
content string
The text content of the htpasswd file.
allowPlaintextPasswords bool
true to compare an entry whose format is not recognized against the password as plaintext; false to 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.cs

Verifies a username and password against the current htpasswd entries.

public bool VerifyCredentials(ReadOnlySpan<char> username, ReadOnlySpan<char> password)
Parameters
username ReadOnlySpan<char>
The username to verify.
password ReadOnlySpan<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.cs

Verifies a username and password against the current htpasswd entries.

public bool VerifyCredentials(string username, string password)
Parameters
username string
The username to verify.
password string
The plaintext password to verify. A password longer than 1024 characters is always rejected.
Returns

bool true if the credentials are valid; otherwise, false.