c# LDAP 验证
来源:互联网 发布:pp越狱助手mac版 编辑:程序博客网 时间:2024/06/11 00:26
using System;using System.Text;using System.Collections;using System.DirectoryServices;namespace FormsAuth{ public class LdapAuthentication { private string _path; private string _filterAttribute; public LdapAuthentication(string path) { _path = path; } public bool IsAuthenticated(string domain, string username, string pwd) { string domainAndUsername = domain + @"\" + username; DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd); try { //Bind to the native AdsObject to force authentication. object obj = entry.NativeObject; DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "(SAMAccountName=" + username + ")"; search.PropertiesToLoad.Add("cn"); SearchResult result = search.FindOne(); if(null == result) { return false; } //Update the new path to the user in the directory. _path = result.Path; _filterAttribute = (string)result.Properties["cn"][0]; } catch (Exception ex) { throw new Exception("Error authenticating user. " + ex.Message); } return true; } public string GetGroups() { DirectorySearcher search = new DirectorySearcher(_path); search.Filter = "(cn=" + _filterAttribute + ")"; search.PropertiesToLoad.Add("memberOf"); StringBuilder groupNames = new StringBuilder(); try { SearchResult result = search.FindOne(); int propertyCount = result.Properties["memberOf"].Count; string dn; int equalsIndex, commaIndex; for(int propertyCounter = 0; propertyCounter < propertyCount; propertyCounter++) { dn = (string)result.Properties["memberOf"][propertyCounter]; equalsIndex = dn.IndexOf("=", 1); commaIndex = dn.IndexOf(",", 1); if(-1 == equalsIndex) { return null; } groupNames.Append(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1)); groupNames.Append("|"); } } catch(Exception ex) { throw new Exception("Error obtaining group names. " + ex.Message); } return groupNames.ToString(); }}}
- LDAP C#验证用户名
- c# LDAP 验证
- C# 用 LDAP 验证用户名和密码
- C#使用Domino的LDAP服务验证用户
- C#使用Domino的LDAP服务验证用户
- C#使用Domino的LDAP服务验证用户
- LDAP用户验证(Spring-LDAP)
- LDAP用户验证(Spring-LDAP)
- LDAP用户验证(Spring-LDAP)
- tomcat使用ldap验证
- 通过LDAP验证
- Java LDAP用户密码验证
- 迈瑞ldap用户验证
- Java Ldap验证
- Gerrit+Ldap登陆验证
- C# LDAP认证登录
- C# LDAP认证登录
- C# LDAP认证登录
- [技术分享-ISA/TMG]怎样在 ISA 或者 TMG 上禁止 IPv6 tunneling
- ubuntu 下ethtool安装
- 嵌入式ARM微处理器选型指南
- 关于 Debug Error! R6010 abort() has been call
- 操作系统练习题(2)
- c# LDAP 验证
- [代码收集] 窗口截屏并保存为bmp图片
- Android之Gallery
- MFC 常见窗口操作
- C++学习总结
- ARM处理器选型指南:选ARM7还是选Cortex-M3
- K2 blackpearl 流程开发(一)
- Silverlight自定义漂亮的ListBox
- Linux查看版本命令