Windows 2000 中 winforms 的 Windows 身份验证

发布于 2024-09-03 05:17:50 字数 688 浏览 0 评论 0原文

我使用以下代码通过我的 winform 应用程序的 Windows 身份验证来验证用户。这在 Windows XP 中工作正常,但当用户使用 Windows 2000 时,它会说用户 ID 或密码有效。

我如何在 Windows 2000 中执行此操作。此外,如何检测用户使用的是 Windows Xp 还是 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;
    }

谢谢

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 this 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥醉 2024-09-10 05:17:50

LogonUser 文档

Windows 2000:如果您需要验证
凭据,使用 SSPI API。为了
有关使用 SSPI API 的信息,
请参阅如何验证用户凭据
在 Microsoft 操作系统上
。使用
LogonUserLogonUserEx 函数
如果您需要通过以下方式冒充用户
使用返回的访问令牌和
访问资源。

要检查您运行的 Windows 版本,请检查 <代码>Environment.OSVersion.Version

Windows 2000是5.0; XP 是 5.2。

此外,您需要通过调用CloseHandle

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文