Namespace: System.Net.Security
Assembly: System.dll
Represents a network credential consisting of a user's username and password.
public sealed class NetworkCredential
The NetworkCredential
class is used to provide credentials for network authentication. This can include usernames, passwords, and domain names. It is commonly used with classes like NetworkCredential
and FtpWebRequest
to authenticate with network resources.
When working with sensitive information like passwords, it is important to handle them securely. Consider using more secure storage mechanisms or encryption where appropriate.
Initializes a new instance of the NetworkCredential
class.
Initializes a new instance of the NetworkCredential
class with the specified user name.
Initializes a new instance of the NetworkCredential
class with the specified user name and password.
Initializes a new instance of the NetworkCredential
class with the specified user name, password, and domain.
Gets or sets the domain associated with the network credential.
string Domain { get; set; }
Gets or sets the password associated with the network credential.
string Password { get; set; }
Gets or sets the user name associated with the network credential.
string UserName { get; set; }
Returns the hash code for this instance.
public override int GetHashCode()
Returns a string representation of the NetworkCredential
object.
public override string ToString()
public NetworkCredential()
Initializes a new instance of the NetworkCredential
class with default values (empty strings for username, password, and domain).
public NetworkCredential(string userName)
Initializes a new instance of the NetworkCredential
class with the specified user name. The password and domain will be empty strings.
public NetworkCredential(string userName, string password)
Initializes a new instance of the NetworkCredential
class with the specified user name and password. The domain will be an empty string.
public NetworkCredential(string userName, string password, string domain)
Initializes a new instance of the NetworkCredential
class with the specified user name, password, and domain.
public string Domain { get; set; }
Gets or sets the domain associated with the network credential. This property can be an empty string if no domain is specified.
public string Password { get; set; }
Gets or sets the password associated with the network credential. This property can be an empty string if no password is provided.
public string UserName { get; set; }
Gets or sets the user name associated with the network credential. This property can be an empty string if no user name is provided.
public override int GetHashCode()
Returns the hash code for this instance. The hash code is based on the user name, password, and domain.
public override string ToString()
Returns a string representation of the NetworkCredential
object. The format is typically "UserName
", "Domain\UserName
", or "UserName:Password
" depending on whether a domain is specified.