Пример #1
0
        private void SplitUsername(string username, ref string parsedUserName, ref string parsedDomainName)
        {
            // If the user has passed null creds then parsed components should also be null.
            if (username == null)
            {
                parsedDomainName = null;
                parsedUserName   = null;
                return;
            }

            // Logon user expects the username in UPN or to have the username and domain split to the separate parameters.
            // It does not work properly with NT4 style name formats.  This function will put the username in the proper format.
            StringBuilder splitUsername = new StringBuilder(UnsafeNativeMethods.CRED_MAX_USERNAME_LENGTH);
            StringBuilder splitDomain   = new StringBuilder(UnsafeNativeMethods.CRED_MAX_DOMAIN_TARGET_LENGTH);

            int result = UnsafeNativeMethods.CredUIParseUserName(
                username,
                splitUsername,
                (System.UInt32)splitUsername.Capacity,
                splitDomain,
                (System.UInt32)splitDomain.Capacity);

            // If CredUiParseUsername fails then username format must have been in a format it does not expect.
            // Just pass then entire username as the user passed it with a null domain string.
            if (result != 0)
            {
                parsedDomainName = null;
                parsedUserName   = username;
            }
            else
            {
                parsedDomainName = splitDomain.ToString();
                parsedUserName   = splitUsername.ToString();
            }
        }
Пример #2
0
 private void SplitUsername(string username, ref string parsedUserName, ref string parsedDomainName)
 {
     if (username != null)
     {
         StringBuilder stringBuilder  = new StringBuilder(0x202);
         StringBuilder stringBuilder1 = new StringBuilder(0x152);
         int           num            = UnsafeNativeMethods.CredUIParseUserName(username, stringBuilder, stringBuilder.Capacity, stringBuilder1, stringBuilder1.Capacity);
         if (num == 0)
         {
             parsedDomainName = stringBuilder1.ToString();
             parsedUserName   = stringBuilder.ToString();
             return;
         }
         else
         {
             parsedDomainName = null;
             parsedUserName   = username;
             return;
         }
     }
     else
     {
         parsedDomainName = null;
         parsedUserName   = null;
         return;
     }
 }