MemoryMappedFile support on Windows
[mono.git] / mcs / class / System / System.Net / NetworkCredential.cs
index 5eea32028f2b8ecbbdd6eaf588d3214ad00470c3..faba55dd4fe05654831e9b0c02be46146bc7198c 100644 (file)
@@ -1,11 +1,13 @@
 //
 // System.Net.NetworkCredential.cs
 //
-// Author: Duncan Mak (duncan@ximian.com)
+// Authors: Duncan Mak (duncan@ximian.com)
+//          Rolf Bjarne KVinge (rolf@xamarin.com)
+//          Marek Safar (marek.safar@gmail.com)
 //
 // (C) Ximian, Inc.
-//
-
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2011, 2014 Xamarin Inc (http://www.xamarin.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Security;
+
 namespace System.Net
 {
        public class NetworkCredential : ICredentials
-#if NET_2_0
                                        , ICredentialsByHost
-#endif
        {
                // Fields
                string userName;
                string password;
                string domain;
                
+               SecureString securePassword;
+
                // Constructors
                public NetworkCredential ()
-                       : base ()
                {
                }
 
@@ -52,42 +55,58 @@ namespace System.Net
                }
 
                public NetworkCredential (string userName, string password, string domain)
+                       : this (userName, password)
                {
-                       this.userName = userName;
-                       this.password = password;
                        this.domain = domain;
                }
 
-               // Properties
+               public NetworkCredential (string userName, SecureString password)
+               {
+                       this.userName = userName;
+                       SecurePassword = password;
+               }
 
-               public string Domain
+               public NetworkCredential (string userName, SecureString password, string domain)
+                       : this (userName, password)
                {
-                       get { return domain; }
+                       this.domain = domain;
+               }
+               // Properties
+
+               public string Domain {
+                       get { return domain ?? String.Empty; }
                        set { domain = value; }
                }
 
-               public string UserName
-               {
-                       get { return userName; }
+               public string UserName {
+                       get { return userName ?? String.Empty; }
                        set { userName = value; }                       
                }
 
-               public string Password
-               {
-                       get { return password; }
+               public string Password {
+                       get { return password ?? String.Empty; }
                        set { password = value; }
                }
 
+               public SecureString SecurePassword {
+                       get { return securePassword; }
+                       set {
+                               if (value == null) {
+                                       securePassword = new SecureString ();
+                               } else {
+                                       securePassword = value;
+                               }
+                       }
+               }
+
                public NetworkCredential GetCredential (Uri uri, string authType)
                {
                        return this;
                }
 
-#if NET_2_0
                public NetworkCredential GetCredential (string host, int port, string authenticationType)
                {
                        return this;
                }
-#endif
        }
 }