在组策略中设置最小密码长度

Setting the minimum password length in Group Policy

我用windowsAPINetUserModalsSet函数写了一段代码来设置最小密码长度。 现在,它有不同的级别(结构)来设置我们想要的

USER_MODALS_INFO_0 this structure allows us to give a maimum value for the password length as LM20_PWLEN(14). If any value greater than this is given, it returns Invalid parameters error. But since i want to set it to more than that, i used USER_MODALS_INFO_1001 因为它允许 PWLEN(256).

当我使用密码长度> 14 的USER_MODALS_INFO_1001 结构时,出现returns 无效参数错误。但如果我将它定义为 14,它就可以正常工作。现在这应该适用于任何长度 <= 256 的密码,但没有。

出现这种行为是否有原因?我附上了我的代码片段

    USER_MODALS_INFO_1001 pBufPass;
    DWORD mode = 1001, value = 17,parm_err;
    printf("The minimum password length is going to be set as %lu\n",value);
    pBufPass.usrmod1001_min_passwd_len = value;
    printf("Value that is going to be set is : %lu\n",pBufPass.usrmod1001_min_passwd_len);
    NET_API_STATUS nStatus = NetUserModalsSet(NULL, mode, (LPBYTE)&pBufPass, &parm_err);
    if (nStatus != NERR_Success)
    {
        printf("Error while using NetUserModalsSet. Error code : %lu and parm_err : %lu\n", nStatus, parm_err);
        ret = false;
    }

对于 USER_MODALS_INFO_1001 结构的参数 usrmod1001_min_passwd_len

  • Windows7支持值0和14

  • Windows10(测试版1903)支持值在0和256之间(PWLEN).