首页 文章

验证域用户凭据

提问于
浏览
2

我需要一种方法来验证Windows上本机c的用户/密码对 . 输入是用户和密码,用户可以是DOMAIN \用户格式 .

基本上我需要编写一个函数:如果用户/密码是有效的本地帐户,则返回true . (第1部分)如果用户/密码在给定的域上有效,也返回true . (第2部分)否则返回false .

使用KB180548我解决了(第1部分)(但我还必须检查用户名是否是有效用户,因为密码空白的用户失败 - 丑陋的解决方法但它有效)

但是对于除“ . ”之外的任何域,上述KB示例代码对任何用户/传递对都有效(不正确) .

我尝试过使用ldap_bind_s,但它成功用于不正确的用户/传递对(可怕的Guest帐户?) . 另外,对于“ . ”域,它对LDAP_SERVER_DOWN的有效用户/密码失败(可能是因为本地主机不是域控制器?)

也许其中一些概念对我来说不清楚 . 我希望至少我的问题得到解释清楚 . 我并没有停留在任何方法上,因为它只能在C本机代码中实现 .

这个问题C#: How to validate domain credentials?好像已经弄明白了(除了没有接受的答案) . 唉,它在C#中 .

编辑:来吧,Stack Overflow,你从来没有让我失望过......

2 回答

  • 1

    如果你的意思是“ . ”域,不受“信任”的域与运行代码的域失败,那就是设计 .

    几年前,当我们使用支持票时,微软最好的答案就是使用WNetUseConnection() .

  • 1

    旧的代码和平,我无法测试,因此给出了:

    //---------------------------------------------------------
    // quick ADSI sample - binding to a user 
    //---------------------------------------------------------
    
    //---------------------------------------------------------
    // should use unicode - saves a lot of conversion work
    //---------------------------------------------------------
    #define _UNICODE
    
    //---------------------------------------------------------
    // libraries needed to use ADSI
    //---------------------------------------------------------
    #pragma comment( lib, "Activeds.lib" )
    #pragma comment( lib, "Adsiid.lib" )
    
    //---------------------------------------------------------
    // ADSI header
    //---------------------------------------------------------
    #include <activeds.h>
    
    int wmain( int argc, wchar_t *argv[] )
    {
      //-----------------------------------------------------
      // HRESULT hr is the return code value from all ADSI
      // calls - using the SUCCEEDED MACRO to check for 
      // success
      //-----------------------------------------------------
      HRESULT hr;
    
      //-----------------------------------------------------
      // pointer to our IADsUser object
      //-----------------------------------------------------
      IADsUser *pUser = NULL;
    
      //-----------------------------------------------------
      // path to the user we are going to try to update
      // make sure you replace this with something
      // specific to your environment
      // Form : WinNT://<domain name>/<object name>,<object class>
      //-----------------------------------------------------
      LPWSTR pszADsPath = L"WinNT://yourdomain/object name,user";
      // 
      // See available forms :
      // http://msdn.microsoft.com/en-us/library/aa746534(v=VS.85).aspx
    
      //-----------------------------------------------------
      // intialize the COM subsystem before doing any work
      //-----------------------------------------------------
      CoInitialize(NULL);
    
      //-----------------------------------------------------
      // try to get the user
      // http://msdn.microsoft.com/en-us/library/aa772184(v=VS.85).aspx
      //-----------------------------------------------------
      hr = ADsGetObject(pszADsPath, IID_IADsUser,(void**)&pUser);
    
      // Here Test hr
      //http://msdn.microsoft.com/en-us/library/aa772195(v=VS.85).aspx
    
      //-----------------------------------------------------
      // kill the COM subsystem we were using
      //-----------------------------------------------------
      CoUninitialize();
    
      return 0;
    }
    

相关问题