添加引用:
using System.Runtime.InteropServices;
public class VerifyUserByDomain { private static int LOGon32_LOGon_INTERACTIVE = 2; private static int LOGon32_PROVIDER_DEFAULT = 0; private static IntPtr tokenHandle = new IntPtr(0); [DllImport("advapi32.dll")] private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken); public static bool verify(string userName, string pwd, string domain) { bool boolResult = false; tokenHandle = IntPtr.Zero; //使用域密码登录 boolResult = LogonUser(userName, domain, pwd, LOGon32_LOGon_INTERACTIVE, LOGon32_PROVIDER_DEFAULT, ref tokenHandle); return boolResult; }
原文:http://www.cnblogs.com/mq0036/p/6397061.html