使用Windows身份验证的C# [英] C# using windows authentication

查看:590
本文介绍了使用Windows身份验证的C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows应用程序,我想在应用程序的开头使用Windows身份验证登录,请提供帮助!

I have a windows application I want to use windows authentication log in at the beginning of my application please help!

推荐答案

class Program
    {

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

        static void Main(string[] args)
        {
            Program obj = new Program();
            bool isValid = obj.IsValidateCredentials("myUserName","MyPassword","MyDomain");
            Console.WriteLine(isValid == true ? "Valid User details" : "Invalid User Details");
            Console.Read();
        }

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


也许是这样的: User登录WinForm应用程序 [ ^ ]
Maybe this: User Login For WinForm Applications[^]


这篇关于使用Windows身份验证的C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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