Overview
Represents credential information for HTTP basic authentication and HTTP digest authentication.
This class is used to provide username and password credentials for authenticating with an HTTP server. It supports both basic and digest authentication schemes.
When making requests to a web server that requires authentication, you can use an instance of UsernameTokenCredential to supply the necessary credentials.
Syntax
public sealed class UsernameTokenCredential : System.Net.NetworkCredential
Members
Constructors
| Name | Description |
|---|---|
| UsernameTokenCredential(string, string) | Initializes a new instance of the UsernameTokenCredential class with the specified username and password. |
Properties
| Name | Description |
|---|---|
| Domain | Gets or sets the domain of the credential. (Inherited from NetworkCredential) |
| Password | Gets or sets the password for the credential. (Inherited from NetworkCredential) |
| UserName | Gets or sets the user name for the credential. (Inherited from NetworkCredential) |
Methods
| Name | Description |
|---|---|
| GetHash() | Calculates and returns the hash of the username and password. |
Requirements
| Component | Version |
|---|---|
| .NET Framework | Supported in: 4.5, 4.0, 3.5, 3.0, 2.0 Client Profiles supported in: 4.5, 4.0 |
| .NET | Supported in: .NET Core 1.0, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0 .NET Standard supported in: 2.0, 2.1 |
| Mono | Supported in: 2.0 |
| UWP | Supported in: 10.0 |
Namespace
Use `System.Net.Security`
Assembly
System.Net.Primitives.dll (for .NET Core, .NET 5+), System (for .NET Framework)
See Also
UsernameTokenCredential(string, string)
Initializes a new instance of the UsernameTokenCredential class with the specified username and password.
public UsernameTokenCredential(string userName, string password);
Parameters
| Name | Type | Description |
|---|---|---|
userName |
string |
The username. |
password |
string |
The password. |
Domain
Gets or sets the domain of the credential.
public string Domain { get; set; }
This property is inherited from the NetworkCredential class.
Password
Gets or sets the password for the credential.
public string Password { get; set; }
This property is inherited from the NetworkCredential class.
UserName
Gets or sets the user name for the credential.
public string UserName { get; set; }
This property is inherited from the NetworkCredential class.
GetHash()
Calculates and returns the hash of the username and password.
public string GetHash();
Returns
string: The calculated hash value.