`
weixing
  • 浏览: 80065 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

验证AD账号、密码

    博客分类:
  • .NET
 
阅读更多

using System.DirectoryServices;

 

 

        //srvr = ldap server, e.g. LDAP://sohu.com
        //usr = user name
        //pwd = user password

        //用法:IsAuthenticated("LDAP://sohu.com", "0140001", "123456"


        public bool IsAuthenticated(string srvr, string usr, string pwd)
        {
            bool authenticated = false;

            try
            {
                DirectoryEntry entry = new DirectoryEntry(srvr, usr, pwd);
                object nativeObject = entry.NativeObject;
                authenticated = true;
            }
            catch (DirectoryServicesCOMException cex)
            {
                //not authenticated; reason why is in cex
            }
            catch (Exception ex)
            {
                //not authenticated due to some other exception [this is optional]
            }
            return authenticated;
        }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics