Dotnet:-如何在窗口表单应用程序中实现Windows身份验证? [英] Dotnet :- How to achieve windows authentication in window form application?

查看:76
本文介绍了Dotnet:-如何在窗口表单应用程序中实现Windows身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个Windows窗体应用程序,并想使用Windows身份验证登录用户,所以必须在Intranet中使用它。应用程序应接受用户的用户名和密码并进行身份验证。

I want to make a windows form application and want to use windows authentication to log in the user, it has to be used in intranet. the applcation should accept the user name and password from user and should authenticate it. how to achieve this.

推荐答案

您可以使用Interop Services实现此目的。使用下面的代码。

You can achieve this using Interop Services. Use the below Code.

    [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, 3, 0, ref tokenHandler);
        return isValid;
    }

这篇关于Dotnet:-如何在窗口表单应用程序中实现Windows身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆