从密码政策中获取信息

时间:2013-03-12 10:03:00

标签: c++ windows passwords

有没有办法从密码政策中获取一些信息?像密码长度,最大密码年龄等

我尝试在注册表中查找但未找到我要找的内容。

1 个答案:

答案 0 :(得分:3)

您可以使用NetUserModalsGet。这是获取MaximumPasswordAge

的示例
int GetMaximumPasswordAge()
    {
        int Age = -1;
         DWORD dwLevel = 0;
       USER_MODALS_INFO_0 *pBuf = NULL;
       NET_API_STATUS nStatus;
       LPTSTR pszServerName = NULL;


       //
       nStatus = NetUserModalsGet((LPCWSTR) pszServerName,
                                  dwLevel,
                                  (LPBYTE *)&pBuf);
       //
       // If the call succeeds, print the global information.
       //
       if (nStatus == NERR_Success)
       {
          if (pBuf != NULL)
          {
              Age = pBuf->usrmod0_max_passwd_age/86400;

             printf("\tMinimum password length:  %d\n", pBuf->usrmod0_min_passwd_len);

          }
       }
       // Otherwise, print the system error.
       //
       else

          fprintf(stderr, "A system error has occurred: %d\n", nStatus);
       //
       // Free the allocated memory.
       //
       if (pBuf != NULL)
          NetApiBufferFree(pBuf);
        return Age;
    }