mscorlib(4.0.0.0) API with additions
NetworkCredential.cs
1 using System.Security;
3 
4 namespace System.Net
5 {
7  [global::__DynamicallyInvokable]
9  {
10  private static volatile EnvironmentPermission m_environmentUserNamePermission;
11 
12  private static volatile EnvironmentPermission m_environmentDomainNamePermission;
13 
14  private static readonly object lockingObject = new object();
15 
16  private string m_domain;
17 
18  private string m_userName;
19 
20  private SecureString m_password;
21 
24  [global::__DynamicallyInvokable]
25  public string UserName
26  {
27  [global::__DynamicallyInvokable]
28  get
29  {
30  InitializePart1();
31  m_environmentUserNamePermission.Demand();
32  return InternalGetUserName();
33  }
34  [global::__DynamicallyInvokable]
35  set
36  {
37  if (value == null)
38  {
39  m_userName = string.Empty;
40  }
41  else
42  {
43  m_userName = value;
44  }
45  }
46  }
47 
50  [global::__DynamicallyInvokable]
51  public string Password
52  {
53  [global::__DynamicallyInvokable]
54  get
55  {
56  ExceptionHelper.UnmanagedPermission.Demand();
57  return InternalGetPassword();
58  }
59  [global::__DynamicallyInvokable]
60  set
61  {
62  m_password = UnsafeNclNativeMethods.SecureStringHelper.CreateSecureString(value);
63  }
64  }
65 
70  {
71  get
72  {
73  ExceptionHelper.UnmanagedPermission.Demand();
74  return InternalGetSecurePassword().Copy();
75  }
76  set
77  {
78  if (value == null)
79  {
80  m_password = new SecureString();
81  }
82  else
83  {
84  m_password = value.Copy();
85  }
86  }
87  }
88 
91  [global::__DynamicallyInvokable]
92  public string Domain
93  {
94  [global::__DynamicallyInvokable]
95  get
96  {
97  InitializePart1();
98  m_environmentDomainNamePermission.Demand();
99  return InternalGetDomain();
100  }
101  [global::__DynamicallyInvokable]
102  set
103  {
104  if (value == null)
105  {
106  m_domain = string.Empty;
107  }
108  else
109  {
110  m_domain = value;
111  }
112  }
113  }
114 
116  [global::__DynamicallyInvokable]
118  : this(string.Empty, string.Empty, string.Empty)
119  {
120  }
121 
125  [global::__DynamicallyInvokable]
126  public NetworkCredential(string userName, string password)
127  : this(userName, password, string.Empty)
128  {
129  }
130 
135  public NetworkCredential(string userName, SecureString password)
136  : this(userName, password, string.Empty)
137  {
138  }
139 
144  [global::__DynamicallyInvokable]
145  public NetworkCredential(string userName, string password, string domain)
146  {
147  UserName = userName;
148  Password = password;
149  Domain = domain;
150  }
151 
157  public NetworkCredential(string userName, SecureString password, string domain)
158  {
159  UserName = userName;
160  SecurePassword = password;
161  Domain = domain;
162  }
163 
164  private void InitializePart1()
165  {
166  if (m_environmentUserNamePermission == null)
167  {
168  lock (lockingObject)
169  {
170  if (m_environmentUserNamePermission == null)
171  {
172  m_environmentDomainNamePermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, "USERDOMAIN");
173  m_environmentUserNamePermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, "USERNAME");
174  }
175  }
176  }
177  }
178 
179  internal string InternalGetUserName()
180  {
181  return m_userName;
182  }
183 
184  internal string InternalGetPassword()
185  {
186  return UnsafeNclNativeMethods.SecureStringHelper.CreateString(m_password);
187  }
188 
189  internal SecureString InternalGetSecurePassword()
190  {
191  return m_password;
192  }
193 
194  internal string InternalGetDomain()
195  {
196  return m_domain;
197  }
198 
199  internal string InternalGetDomainUserName()
200  {
201  string text = InternalGetDomain();
202  if (text.Length != 0)
203  {
204  text += "\\";
205  }
206  return text + InternalGetUserName();
207  }
208 
213  [global::__DynamicallyInvokable]
214  public NetworkCredential GetCredential(Uri uri, string authType)
215  {
216  return this;
217  }
218 
224  [global::__DynamicallyInvokable]
225  public NetworkCredential GetCredential(string host, int port, string authenticationType)
226  {
227  return this;
228  }
229  }
230 }
SecureString SecurePassword
Gets or sets the password as a T:System.Security.SecureString instance.
NetworkCredential GetCredential(string host, int port, string authenticationType)
Returns an instance of the T:System.Net.NetworkCredential class for the specified host,...
Definition: __Canon.cs:3
EnvironmentPermissionAccess
Specifies access to environment variables.
SecureString Copy()
Creates a copy of the current secure string.
NetworkCredential(string userName, SecureString password)
Initializes a new instance of the T:System.Net.NetworkCredential class with the specified user name a...
string Password
Gets or sets the password for the user name associated with the credentials.
NetworkCredential()
Initializes a new instance of the T:System.Net.NetworkCredential class.
Represents text that should be kept confidential, such as by deleting it from computer memory when no...
Definition: SecureString.cs:11
Provides the interface for retrieving credentials for a host, port, and authentication type.
Provides the base authentication interface for retrieving credentials for Web client authentication.
Definition: ICredentials.cs:5
string UserName
Gets or sets the user name associated with the credentials.
NetworkCredential(string userName, SecureString password, string domain)
Initializes a new instance of the T:System.Net.NetworkCredential class with the specified user name,...
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
NetworkCredential(string userName, string password, string domain)
Initializes a new instance of the T:System.Net.NetworkCredential class with the specified user name,...
string Domain
Gets or sets the domain or computer name that verifies the credentials.
NetworkCredential(string userName, string password)
Initializes a new instance of the T:System.Net.NetworkCredential class with the specified user name a...
Controls access to system and user environment variables. This class cannot be inherited.
NetworkCredential GetCredential(Uri uri, string authType)
Returns an instance of the T:System.Net.NetworkCredential class for the specified Uniform Resource Id...
Provides credentials for password-based authentication schemes such as basic, digest,...
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
Definition: Uri.cs:19