Search code examples
c++winapipolicy

Setting the minimum password length in Group Policy


I wrote a code using the windows API NetUserModalsSet function to set the minimum password length. Now, this has different levels(structures) to set what we want

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 as it allows PWLEN(256).

When i use the USER_MODALS_INFO_1001 structure with a password length > 14, it returns invalid parameter error. But if i define it as 14, it is working properly. Now this should have worked with any password length <= 256 but didn't.

Is there a reason why this is exhibiting this behavior? I have attached a snippet of my code

    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;
    }

Solution

  • For parameter usrmod1001_min_passwd_len of USER_MODALS_INFO_1001 structure:

    • Windows 7 support value 0 and 14.

    • Windows 10 (test version 1903) support value between 0 and 256 (PWLEN).