示例#1
0
        public SafeFreeNegoCredentials(string username, string password, string domain) : base(IntPtr.Zero, true)
        {
            bool ignore = false;

            _credential = SafeGssCredHandle.Create(username, password, domain);
            _credential.DangerousAddRef(ref ignore);
        }
示例#2
0
        public SafeFreeNegoCredentials(bool isNtlmOnly, string username, string password, string domain)
            : base(IntPtr.Zero, true)
        {
            Debug.Assert(username != null && password != null, "Username and Password can not be null");
            const char At        = '@';
            const char Backwhack = '\\';

            // any invalid user format will not be mnipulated and passed as it is.
            int index = username.IndexOf(Backwhack);

            if (index > 0 && username.IndexOf(Backwhack, index + 1) < 0 && string.IsNullOrEmpty(domain))
            {
                domain   = username.Substring(0, index);
                username = username.Substring(index + 1);
            }

            // remove any leading and trailing whitespace
            if (domain != null)
            {
                domain = domain.Trim();
            }

            if (username != null)
            {
                username = username.Trim();
            }

            if ((username.IndexOf(At) < 0) && !string.IsNullOrEmpty(domain))
            {
                username += At + domain;
            }

            bool ignore = false;

            _isNtlmOnly = isNtlmOnly;
            _userName   = username;
            _isDefault  = string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password);
            _credential = SafeGssCredHandle.Create(username, password, isNtlmOnly);
            _credential.DangerousAddRef(ref ignore);
        }
 public static void GetDefaultKerberosCredentials(string username, string password)
 {
     // Fetch a Kerberos TGT which gets saved in the default cache
     SafeGssCredHandle.Create(username, password, isNtlmOnly: false).Dispose();
 }