遗失的星空

导航

C#域验证的代码

using System.Runtime.InteropServices;

protected bool fun_AuthDomainUser(string username, string domain, string passwd)
    {
        const int LOGON32_LOGON_INTERACTIVE = 2; //通过网络验证账户合法性
        const int LOGON32_PROVIDER_DEFAULT = 0; //使用默认的Windows 2000/NT NTLM验证方
        IntPtr tokenHandle = new IntPtr(0);
        tokenHandle = IntPtr.Zero;

        bool checkok = LogonUser(username, domain, passwd, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref tokenHandle);
        return checkok;
    }

    [DllImport("advapi32.dll")]
    private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

posted on 2011-09-06 15:37  遗失的星空  阅读(672)  评论(0编辑  收藏  举报