NetworkCredential.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // System.Net.NetworkCredential.cs
  3. //
  4. // Authors: Duncan Mak ([email protected])
  5. // Rolf Bjarne KVinge ([email protected])
  6. // Marek Safar ([email protected])
  7. //
  8. // (C) Ximian, Inc.
  9. // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
  10. // Copyright (C) 2011, 2014 Xamarin Inc (http://www.xamarin.com)
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System.Security;
  32. namespace System.Net
  33. {
  34. public class NetworkCredential : ICredentials
  35. , ICredentialsByHost
  36. {
  37. // Fields
  38. string userName;
  39. string password;
  40. string domain;
  41. #if NET_4_0
  42. SecureString securePassword;
  43. #endif
  44. // Constructors
  45. public NetworkCredential ()
  46. {
  47. }
  48. public NetworkCredential (string userName, string password)
  49. {
  50. this.userName = userName;
  51. this.password = password;
  52. }
  53. public NetworkCredential (string userName, string password, string domain)
  54. : this (userName, password)
  55. {
  56. this.domain = domain;
  57. }
  58. #if NET_4_0
  59. public NetworkCredential (string userName, SecureString password)
  60. {
  61. this.userName = userName;
  62. SecurePassword = password;
  63. }
  64. public NetworkCredential (string userName, SecureString password, string domain)
  65. : this (userName, password)
  66. {
  67. this.domain = domain;
  68. }
  69. #endif
  70. // Properties
  71. public string Domain {
  72. get { return domain ?? String.Empty; }
  73. set { domain = value; }
  74. }
  75. public string UserName {
  76. get { return userName ?? String.Empty; }
  77. set { userName = value; }
  78. }
  79. public string Password {
  80. get { return password ?? String.Empty; }
  81. set { password = value; }
  82. }
  83. #if NET_4_0
  84. public SecureString SecurePassword {
  85. get { return securePassword; }
  86. set {
  87. if (value == null) {
  88. securePassword = new SecureString ();
  89. } else {
  90. securePassword = value;
  91. }
  92. }
  93. }
  94. #endif
  95. public NetworkCredential GetCredential (Uri uri, string authType)
  96. {
  97. return this;
  98. }
  99. public NetworkCredential GetCredential (string host, int port, string authenticationType)
  100. {
  101. return this;
  102. }
  103. }
  104. }