惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
罗磊的独立博客
H
Help Net Security
月光博客
月光博客
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
GbyAI
GbyAI
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - ZH.net

在vb.net中通过ODBC从Oracle 9i向Access倒数据 从SQLSERVER向ORACLE8迁移的技术实现方案 Part V [转] 从SQLSERVER向ORACLE8迁移的技术实现方案 PartIV [转] 从SQLSERVER向ORACLE8迁移的技术实现方案 PartIII [转] 从SQL SERVER向ORACLE的迁移方案[转] PartII Sql Server 转入 Oracle part I (转自网络) 在 .NET 中使用 Oracle 数据库事务 作者:Jason Price 转自oracle.com Oracle Trigger(转自网络) Oracle的分页以及sequence 一些正则表达式 - ZH.net - 博客园 接昨日,将上传至oracle的excel文件下载下来 将文件(word,excel等)存入oracle的一个字段 .net studio 2005操作dbf文件 Web利用Gloabl.asax实现多线程任务 maintain AD(将一个账号移动到另一个群组) 一些JS ViewState的一些学习笔记 发mail时smtp服务器设置的一个问题 datagrid前加checkbox
一個Check AD的类。from MSDN
ZH.net · 2005-09-16 · via 博客园 - ZH.net

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 username, string pwd)
   {
   // string domainAndUsername = domain + @"\" + username;
    string domainAndUsername = username;
    DirectoryEntry entry = new DirectoryEntry(_path);
     
    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
    {
     //throw new Exception("Error authenticating user. " + ex.Message);
     return false;
    }
  
    return true;
   }
  
   public string GetGroups()
   {
   // string _path=_path;
    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();
   }
  }
}