基于Active Directory的用户验证

本文介绍了如何基于Active Directory实现用户验证,包括IsUserValid()方法用于验证用户名和密码的合法性,IsAccountActive()方法检查账号是否启用。还提供了一个Login()方法,它综合运用这两个方法来确保用户存在且账号活动。同时,提到了Domain Password Policy的注意事项,以及可能的登录结果枚举类型.
摘要由CSDN通过智能技术生成

基于Active Directory的用户验证

 

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值