开发者

Windows Authentication for winforms with Windows 2000

I use the following code to validate users through windows authentication for my winform application. This works fine with windows XP but when the user is using windows 2000, it says that the userid or password is in valid.

How do I do thi开发者_Go百科s in Windows 2000. Further, How do I detect whether the user is using Windows Xp or windows 2000.

        [System.Runtime.InteropServices.DllImport("advapi32.dll")]
    public static extern bool LogonUser(string userName, string domainName, string password, int LogonType, int LogonProvider, ref IntPtr phToken);

    public bool IsValidateCredentials(string userName, string password, string domain)
    {
        IntPtr tokenHandler = IntPtr.Zero;
        bool isValid = LogonUser(userName, domain, password, 2, 0, ref tokenHandler);
        return isValid;
    }

Thanks


As stated in the documentation for LogonUser:

Windows 2000: If you need to validate credentials, use the SSPI APIs. For information about using the SSPI APIs, see How To Validate User Credentials on Microsoft Operating Systems. Use the LogonUser or LogonUserEx function if you need to impersonate the user by using the returned access token and access a resource.

To check what version of Windows you're running on, check Environment.OSVersion.Version.

Windows 2000 is 5.0; XP is 5.2.

Also, you need to close the handle by calling CloseHandle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜