예제 #1
0
 public static TokenHandle Logon(string username, string domain, string password, UserLogonType logonType = UserLogonType.Interactive, UserLogonProvider logonProvider = UserLogonProvider.Default)
 {
     TokenHandle tokenHandle;
     if (!NativeMethods.LogonUser(username, domain, password, logonType, logonProvider, out tokenHandle))
     {
         ErrorHelper.ThrowCustomWin32Exception();
     }
     return tokenHandle;
 }
예제 #2
0
 public static TokenHandle Logon(string username, string domain, SecureString password, UserLogonType logonType = UserLogonType.Interactive, UserLogonProvider logonProvider = UserLogonProvider.Default)
 {
     IntPtr passwordPtr = Marshal.SecureStringToGlobalAllocUnicode(password);
     try
     {
         TokenHandle tokenHandle;
         if (!NativeMethods.LogonUser(username, domain, passwordPtr, logonType, logonProvider, out tokenHandle))
         {
             ErrorHelper.ThrowCustomWin32Exception();
         }
         return tokenHandle;
     }
     finally
     {
         Marshal.ZeroFreeGlobalAllocUnicode(passwordPtr);
     }
 }
예제 #3
0
 public IToken Logon(string username, string domain, SecureString password, UserLogonType logonType = UserLogonType.Interactive, UserLogonProvider logonProvider = UserLogonProvider.Default)
 {
     var handle = TokenHandle.Logon(username, domain, password, logonType, logonProvider);
     return new Token(handle);
 }
예제 #4
0
 public static extern bool LogonUser(string username, string domain, string password, UserLogonType logonType, UserLogonProvider logonProvider, out TokenHandle handle);
예제 #5
0
        public static TokenHandle Logon(string username, string domain, string password, UserLogonType logonType = UserLogonType.Interactive, UserLogonProvider logonProvider = UserLogonProvider.Default)
        {
            TokenHandle tokenHandle;

            if (!NativeMethods.LogonUser(username, domain, password, logonType, logonProvider, out tokenHandle))
            {
                ErrorHelper.ThrowCustomWin32Exception();
            }
            return(tokenHandle);
        }
예제 #6
0
        public static TokenHandle Logon(string username, string domain, SecureString password, UserLogonType logonType = UserLogonType.Interactive, UserLogonProvider logonProvider = UserLogonProvider.Default)
        {
            IntPtr passwordPtr = Marshal.SecureStringToGlobalAllocUnicode(password);

            try
            {
                TokenHandle tokenHandle;
                if (!NativeMethods.LogonUser(username, domain, passwordPtr, logonType, logonProvider, out tokenHandle))
                {
                    ErrorHelper.ThrowCustomWin32Exception();
                }
                return(tokenHandle);
            }
            finally
            {
                Marshal.ZeroFreeGlobalAllocUnicode(passwordPtr);
            }
        }
예제 #7
0
 public static extern bool LogonUser(string username, string domain, string password, UserLogonType logonType, UserLogonProvider logonProvider, out TokenHandle handle);
예제 #8
0
        public IToken Logon(string username, string domain, SecureString password, UserLogonType logonType = UserLogonType.Interactive, UserLogonProvider logonProvider = UserLogonProvider.Default)
        {
            var handle = TokenHandle.Logon(username, domain, password, logonType, logonProvider);

            return(new Token(handle));
        }