验证AD账号、密码_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > 验证AD账号、密码

验证AD账号、密码

 2011/1/9 9:19:08  weixing  http://weixing.javaeye.com  我要评论(0)
  • 摘要:usingSystem.DirectoryServices;//srvr=ldapserver,e.g.LDAP://sohu.com//usr=username//pwd=userpassword//用法:IsAuthenticated("LDAP://sohu.com","0140001","123456"publicboolIsAuthenticated(stringsrvr,stringusr,stringpwd){boolauthenticated=false;try
  • 标签:

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

  • 相关文章
发表评论
用户名: 匿名