代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
ADHelper类
作者:
qfb620/
/ 发布于
2014/1/22
/
508
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; using System.DirectoryServices; namespace DPForAD2BPMTel { public class ADHelper { public static String LDAPPath = ConfigurationManager.AppSettings["LDAPPath"]; public static String Domain = ConfigurationManager.AppSettings["Domain"]; public static String DomainUser = ConfigurationManager.AppSettings["DomainUser"]; public static String DomainPass = ConfigurationManager.AppSettings["DomainPass"]; /// <summary> /// 验证AD用户是否登陆成功 /// </summary> /// <param name="domain">域名称</param> /// <param name="username">用户名</param> /// <param name="password">密码</param> /// <returns>返回登陆状态</returns> public static bool TryAuthenticate(string Account, string Password) { bool isLogin = false; try { DirectoryEntry entry = new DirectoryEntry(string.Format(LDAPPath, Domain), Account, Password); entry.RefreshCache(); isLogin = true; } catch { isLogin = false; } return isLogin; } /// <summary> /// 设置指定的属性值 /// </summary> /// <param name="de"></param> /// <param name="propertyName">属性名称?</param> /// <param name="propertyValue">属性值</param> public static void SetProperty(DirectoryEntry de, string propertyName, string propertyValue) { if (de.Properties.Contains(propertyName)) { if (String.IsNullOrEmpty(propertyValue)) { de.Properties[propertyName].RemoveAt(0); } else { de.Properties[propertyName][0] = propertyValue; } } else { if (!String.IsNullOrEmpty(propertyValue)) { de.Properties[propertyName].Add(propertyValue); } } } /// <summary> /// 修改查询到的用户 /// </summary> /// <param name="CommonName">通用名(displayName,系统中显示的中文字)</param> /// <param name="Account">帐户名(如Peter)</param> /// <param name="organizeName">组织单元名(资讯中心)</param> /// <param name="password">密码</param> public static bool ChangePassword(string Account, string NewPassword) { bool isLogin = false; try { DirectoryEntry entry1 = new DirectoryEntry(LDAPPath, DomainUser, DomainPass, AuthenticationTypes.Secure); Object obj = entry1.NativeObject; DirectorySearcher search = new DirectorySearcher(entry1); search.Filter = "(SAMAccountName=" + Account + ")"; search.PropertiesToLoad.Add("cn"); SearchResult result = search.FindOne(); DirectoryEntry user = result.GetDirectoryEntry(); SetProperty(user, "sAMAccountName", Account); user.Invoke("SetPassword", new object[] { NewPassword }); user.CommitChanges(); isLogin = true; } catch { isLogin = false; } return isLogin; } /// <summary> /// 根据员工ID获取对应AD域账号 /// </summary> /// <param name="EmployeeID"></param> /// <returns></returns> public static string GetAccountByEmployeeID(string EmployeeID) { string Account = string.Empty; try { DirectoryEntry entry = new DirectoryEntry(LDAPPath, DomainUser, DomainPass, AuthenticationTypes.Secure); Object obj = entry.NativeObject; DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "EmployeeID=" + EmployeeID;// "(SAMAccountName=qiu.fangbing)"; search.PropertiesToLoad.Add("cn"); SearchResult result = search.FindOne(); DirectoryEntry user = result.GetDirectoryEntry(); Account = Convert.ToString(user.Invoke("Get", new object[] { "SAMAccountName" })); //string AD = user.Properties["SAMAccountName"].Value.ToString(); //string FullName = Convert.ToString(user.Invoke("Get", new object[] { "displayName" })); //string Email = Convert.ToString(user.Invoke("Get", new object[] { "mail" })); //string Path = Convert.ToString(user.Invoke("Get", new object[] { "distinguishedName" })); } catch { Account = string.Empty; } return Account; } /// <summary> /// 根据员工工号获取对应AD信息 /// </summary> /// <param name="EmployeeID"></param> /// <returns></returns> public static ADInfo GetInfoByEmployeeID(string EmployeeID) { ADInfo info = new ADInfo(); try { DirectoryEntry entry = new DirectoryEntry(LDAPPath, DomainUser, DomainPass, AuthenticationTypes.Secure); Object obj = entry.NativeObject; DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "EmployeeID=" + EmployeeID;// "(SAMAccountName=qiu.fangbing)"; search.PropertiesToLoad.Add("cn"); SearchResult result = search.FindOne(); DirectoryEntry user = result.GetDirectoryEntry(); info.Account = Convert.ToString(user.Invoke("Get", new object[] { "SAMAccountName" })); info.EmployeeID = Convert.ToString(user.Invoke("Get", new object[] { "EmployeeID" })); info.Tel = Convert.ToString(user.Invoke("Get", new object[] { "telephoneNumber" })); //info.DisplayName = Convert.ToString(user.Invoke("Get", new object[] { "displayName" })); //info.Email = Convert.ToString(user.Invoke("Get", new object[] { "mail" })); //info.Company = Convert.ToString(user.Invoke("Get", new object[] { "physicalDeliveryOfficeName" })); //info.Center = Convert.ToString(user.Invoke("Get", new object[] { "company" })); //info.Department = Convert.ToString(user.Invoke("Get", new object[] { "Department" })); //info.Postion = Convert.ToString(user.Invoke("Get", new object[] { "title" })); //info.Mobile = Convert.ToString(user.Invoke("Get", new object[] { "mobile" })); } catch { info = null; } return info; } } }
试试其它关键字
ADHelper
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
qfb620/
贡献的其它代码
(
5
)
.
GridView中CheckBox,RadioButton并存的同时且有相互关
.
SQL读取信息不重复
.
TextArea的长度限定
.
ADHelper类
.
LogHelper类
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3