C# NT登录验证

C# NT登录验证

/// <summary>
/// 验证NT帐号
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="userPW">密码</param>
/// <returns></returns>       
private bool checkNT(string userName,string userPW)
{
    bool checkOk = false;
    try
    {
         DirectoryEntry dicObj = new DirectoryEntry("WinNT://bqc.corp.com", userName, userPW, AuthenticationTypes.Secure);
         Object native = dicObj.NativeObject;
         checkOk = true;
     }
     catch
     {
          checkOk = false;
      }

       return checkOk;
}

其中的DirectoryEntry()方法要引用System.DirectoryServices程序集。四个参数:1.用户所在域2.用户名3.密码4.权限类型

你可能感兴趣的:(C# NT登录验证)