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

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - 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();
   }
  }
}