基于Active Directory的用户验证
===================
由于需要使用MS的AD用户验证的功能,使AD用户认证成为公司的唯一用户认证的系统,因此,最后一直在找AD用户验证的资料,还好, 找到了如下的资料,非常不错,值得一看!!!
当然,还找到了更好的资源:
通过C#写的一个AD管理的类:http://www.c-sharpcorner.com/Code/2002/Sept/ADClass.asp
1. 基于AD的用户验证
public static bool IsUserValid (string UserName, string Password)
{
using (DirectoryEntry deUser = new DirectoryEntry(ADPath, UserName, Password, AuthenticationTypes.Secure))
{
try
{
// The NativeObject call on the DirectoryEntry object entry is an attempt to bind to the object in the directory.
// Since this call forces authentication, you will get an error if the user does not exist.
// If the user is a valid user in the domain, the call will succeed.
Object native = deUser.NativeObject;
return true;
}
catch
{
return false;
}
}
}
根据UserName/Password验证用户的合法性。需要注意的是:ADSI每次都会尝试Kerberos和NTLM验证,因此系统会记录2次验证记录。在设置Domain Password Policy时,需要考虑到上述的限制。否则,如果Bad Password Count超过限定的Domain Password Policy时,该帐户会Locked out。(注:后面有Article介绍如何判断/如何Lock/Unlock帐户)
2. 验证用户账号Active/Disable
/// <summary>
/// This will perfrom a logical operation on the userAccountControl values
/// to see if the user account is enabled or disabled. The flag for determining if the
/// account is active is a bitwise value (decimal =2)
/// </summary>
/// <param name="userAccountControl"></param>
/// <returns></returns>
public static bool IsAccountActive(int userAccountControl)
{
int userAccountControl_Disabled= Convert.ToInt32(ADAccountOptions.UF_ACCOUNTDISABLE);
int flagExists = userAccountControl & userAccountControl_Disabled;
//if a match is found, then the disabled flag exists within the control flags
if(flagExists >0)
{
return false;
}
else
{
return true;
}
}
3. 示例代码:调用上述IsUserValid()和IsAccountActive()方法
/// <summary>
/// This method will not actually log a user in, but will perform tests to ensure
/// that the user account exists (matched by both the username and password), and also
/// checks if the account is active.
/// </summary>
/// <param name="UserName"></param>
/// <param name="Password"></param>
/// <returns></returns>
public static ADHelper.LoginResult Login(string UserName, string Password)
{
//first, check if the logon exists based on the username and password
//DirectoryEntry de = GetUser(UserName,Password);
if(IsUserValid(UserName,Password))
{
DirectoryEntry de = GetUser(UserName);
if(de !=null)
{
//convert the accountControl value so that a logical operation can be performed
//to check of the Disabled option exists.
int userAccountControl = Convert.ToInt32(de.Properties["userAccountControl"][0]);
de.Close();
//if the disabled item does not exist then the account is active
if(!IsAccountActive(userAccountControl))
{
return LoginResult.LOGIN_USER_ACCOUNT_INACTIVE;
}
else
{
return LoginResult.LOGIN_OK;
}
}
else
{
return LoginResult.LOGIN_USER_DOESNT_EXIST;
}
}
else
{
return LoginResult.LOGIN_USER_DOESNT_EXIST;
}
}
4. 相关enum数据类型:ADAccountOptions和LoginResult
#region Enumerations
public enum ADAccountOptions
{
UF_TEMP_DUPLICATE_ACCOUNT = 0x0100,
UF_NORMAL_ACCOUNT =0x0200,
UF_INTERDOMAIN_TRUST_ACCOUNT =0x0800,
UF_WORKSTATION_TRUST_ACCOUNT = 0x1000,
UF_SERVER_TRUST_ACCOUNT =0x2000,
UF_DONT_EXPIRE_PASSWD=0x10000,
UF_SCRIPT =0x0001,
UF_ACCOUNTDISABLE=0x0002,
UF_HOMEDIR_REQUIRED =0x0008,
UF_LOCKOUT=0x0010,
UF_PASSWD_NOTREQD=0x0020,
UF_PASSWD_CANT_CHANGE=0x0040,
UF_ACCOUNT_LOCKOUT=0X0010,
UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED=0X0080,
}
public enum LoginResult
{
LOGIN_OK=0,
LOGIN_USER_DOESNT_EXIST,
LOGIN_USER_ACCOUNT_INACTIVE
}
#endregion
具体用户界面User Interface,请参考如下Reference 1
http://www.c-sharpcorner.com/Code/2002/Sept/ADClass.asp
分享到:
相关推荐
SearchBlox 文件系统集合搜索结果可以与 Active Directory 集成,以提供基于用户组的安全搜索结果。 为了在 SearchBlox 中设置 Active Directory 身份验证和授权,只需在启动 SearchBlox 之前编辑项目内的 shiro....
以Microsoft Windows PowerShell为基础构建,并与服务器管理器集成后,Windows Server 2012提供了一个更简单、更一致、耗时更少的、基于向导的部署体验。例如,Windows Server 2012只需要一个企业级凭据,即可对多个...
它基于用于 Microsoft Active Directory 的 auth(身份验证)和 authZ(授权)的 ldapjs 客户端(文档)。 如果您想贡献以添加全新的功能和/或节点,请不要犹豫加入并提交您的合并请求! 入门 安装 Node-RED():...
这是基于Microsoft ADAL(Azure Active Directory身份验证库)的Angular 6+(Angular 6.XX和Angular 7.XX)模块的包装库-https: ,可帮助您将Web应用程序与Microsoft的AAD(Azure Active Directory)集成在一起以...
基于Ion Auth的Codeigniter的Active Directory身份验证 此软件可以与Codeigniter 3一起使用,以针对Active Directory域控制器(或Samba4域控制器)进行身份验证。 该软件旨在在Intranet上使用。 安装 确保您使用的...
UmbBackofficeMembershipProvider 允许Umbraco 7.7.2+使用基于MembershipProvider的提供程序进行Active Directory身份验证的代码。 Umbraco 7.4.2-7.7.1的用户应使用UmbBackofficeMembershipProvider 3.0.0( )。 ...
Ansible 角色:libnss-ldap + Active Directory Ansible 角色用于配置基于 Debian 的服务器或使用 ldap 身份验证切换到 Active Directory 服务器。 有关更多详细信息,请参阅上的的 Cumulus Linux 文章要求Ansible ...
Kubernetes的乐团-Active Directory和LDAP Orchestra是一个基于OpenUnison的Kubernetes自动化门户。 Orchestra将用户身份集成到Kubernetes中,从而实现: API服务器和LDAP基础结构之间的SSO Kubernetes仪表板的SSO ...
aad-sso-codeigniter 使用Azure Active Directory对CodeIgniter站点进行身份验证重要提示:这尚未验证令牌,因此绝对不能使用。 使用Azure Active Directory保护对基于CodeIgniter PHP框架的网站或应用程序的访问。 ...
Active Directory 联合身份验证服务 (ADFS) 身份验证 社交媒体登录(Facebook、Twitter、Google+ 和 Microsoft 帐户已实施) OpenId 连接身份验证 记录并显示用户的所有登录尝试 密码复杂度设置 自动跨站请求伪造 ...
二、添加 AD (Active Directory域服务 三、添加 IIS (Internet信息服务) 四、添加 CA (Active Dirctory证书服务) 五、添加 DHCP(DHCP 服务器 六、添加 IAS (网络策略和访问服务) 第三章 基于 802.1X 用户...
现有许多处理LDAP身份验证的dropwizard插件,但没有一个使该作者可以针对Microsoft Active Directory LDAP部署工作(即装即用)。 我不确定这是由于我们的AD服务配置不规范,还是现有插件配置不足以支持Active ...
6.2、任何认证用户都是 Users 组的成员 38 6.3、Anonymous 组不再是 Everyone 组的成员 38 6.4、Anonymous Logon 组中的成员成为本地计算机上 Everyone 组中的成员 38 6.5、公认的安全标识符(特殊标识符) 38 6.6、...
#LDAP AUTH AS PLUGING FOR REVIVE ADSERVER 1.0.0 版作者:Karen Mikaela,电子邮件: ##ABOUT LdapAuth 是一个 Revive(广告服务器)插件,提供 Active Directory 身份验证。 这是对 Revive Community 的贡献。 ##...
基于Alpine Linux的Samba 4 AD容器 学分 部分零件来自: 笔记: 此容器非常适合通过SAMBA AD进行身份验证。 如果您需要用于Windows pc的SAMBA AD,则需要一个VM,使用此Docker容器可以加入AD,但是重新启动后,您...
5.1.2 Windows Server 2003安全概述 Windows Server 2003 系统的安全模型的主要功能是用户身份验证和访问控制及Active Directory 目录服务。 WindowsServer网络安全讲义(PPT-48页)全文共49页,当前为第6页。 身份...
2.windows 验证——允许访问 vnc 服务器以便控制基于标准的 windows 用户证书, 无论其是本地的、nt 域或者基于 active directory。3.windows防火墙集成——使 vnc server 可以更直接的部署。4.文件传输——与 ...
无论其是本地的、NT 域或者基于 Active Directory。 . 单一登录 —— 允许在一个域内部访问 VNC 服务器而不需要重新输入用户的名称和口令。 . 简单但有效的部署 —— 用 VNC Tool,即 VNC Deployment Tool for ...
无论其是本地的、NT 域或者基于 Active Directory。 . 单一登录 —— 允许在一个域内部访问 VNC 服务器而不需要重新输入用户的名称和口令。 . 简单但有效的部署 —— 用 VNC Tool,即 VNC Deployment Tool for ...
Active Directory 身份验证提供程序。 只能与 4) 一起使用 复合身份验证提供程序。 在单个应用程序中支持混合身份验证机制。 可以使用 w/wo 1)。 Restful 身份验证过滤器。 支持通过 JSON 格式的 REST 请求进行...