C# AD域验证登录

2020-12-18 18:32

阅读:627

标签:rgb   new   用户名   ESS   find   ext   entry   pac   password   

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.DirectoryServices;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            var userName = "abc";
            var password = "123456";
            using (DirectoryEntry adsEntry = new DirectoryEntry("LDAP://192.168.0.109", userName, password, AuthenticationTypes.Secure))
            {
                using (DirectorySearcher adsSearcher = new DirectorySearcher(adsEntry))
                {
                    adsSearcher.Filter = "(sAMAccountName=" + userName + ")";
                    try
                    {
                        SearchResult adsSearchResult = adsSearcher.FindOne();
                    }
                    catch (Exception ex)
                    {
                        // 用户名或密码错误
                        string strError = ex.Message;
                    }
                    finally
                    {
                        adsEntry.Close();
                    }
                }
            }
        }
    }
}

 

C# AD域验证登录

标签:rgb   new   用户名   ESS   find   ext   entry   pac   password   

原文地址:https://www.cnblogs.com/xienb/p/14129445.html

上一篇:C#-DL/T 645—2007协议

下一篇:hdfs的相关api


评论


亲,登录后才可以留言!