a oe @sXdZddlZddlZddlmZddlZddlZddlZddZedkrTe edS)a9A demo of using win32net.NetValidatePasswordPolicy. Example usage: % NetValidatePasswordPolicy.py --password=foo change which might return: > Result of 'change' validation is 0: The operation completed successfully. or depending on the policy: > Result of 'change' validation is 2245: The password does not meet the > password policy requirements. Check the minimum password length, > password complexity and password history requirements. Adding --user doesn't seem to change the output (even the PasswordLastSet seen when '-f' is used doesn't depend on the username), but theoretically it will also check the password history for the specified user. % NetValidatePasswordPolicy.py auth which always (with and without '-m') seems to return: > Result of 'auth' validation is 2701: Password must change at next logon N)pprintc Csztjddd}|jddddd|jd d dd d|jd d dddd|jddddd|jdddddd|\}}|sdg}|D]}|dkrd|ji}tj}n,|dkr|j|j|jd}tj }n | dzt |j d||\}}WnTty tdYd St j y>}ztd!|WYd}~d Sd}~00|jrXtd"t|td#||t|fqd$S)%Nz%prog [options] auth|change ...z*A win32net.NetValidatePasswordPolicy demo.) descriptionz-uz --usernamestorezAThe username to pass to the function (only for the change command)actionhelpz-pz --passwordzOThe clear-text password to pass to the function (only for the 'change' command)z-mz--password-matched store_falseTzUsed to specify the password does NOT match (ie, uses False for the PasswordMatch/PasswordMatched arg, both 'auth' and 'change' commands))rdefaultrz-sz--serverz0The name of the server to execute the command onz-fz --show_fields store_trueFz0Print the NET_VALIDATE_PERSISTED_FIELDS returnedZauthZPasswordMatchedZchange)Z ClearPasswordZ PasswordMatchZUserAccountNamez(Invalid arg - must be 'auth' or 'change'z;NetValidatePasswordPolicy not implemented on this platform.z"NetValidatePasswordPolicy failed: z%NET_VALIDATE_PERSISTED_FIELDS fields:z!Result of %r validation is %d: %sr)optparseZ OptionParserZ add_option parse_argsZpassword_matched win32netconZNetValidateAuthenticationpasswordusernameZNetValidatePasswordChangeerrorwin32netZNetValidatePasswordPolicyZserverNotImplementedErrorprintZ show_fieldsrwin32apiZ FormatMessagestrip) parseroptionsargsarginputZval_typefieldsstatusexcrFC:\Program Files\Certbot\pkgs\win32\Demos\NetValidatePasswordPolicy.pymain$s     r __main__) __doc__r sysrrrr r __name__exitrrrrs Z