Dotnet :- How to achieve windows authentication in window form application?

自作多情 提交于 2019-12-02 05:39:36

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;
    }

Environment.UserName gives you the username of the current user. A password is not needed since the user have logged into windows.

Alternative: WindowsIdentity.GetCurrent()

Please refer the following link to apply windows Authentication in Intranet:

http://msdn.microsoft.com/library/bb882216.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!