NetValidatePasswordPolicy.py :  » Windows » pyExcelerator » pywin32-214 » win32 » Demos » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Windows » pyExcelerator 
pyExcelerator » pywin32 214 » win32 » Demos » NetValidatePasswordPolicy.py
"""A 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
"""

import sys
import win32api
import win32net, win32netcon

import optparse
from pprint import pprint

def main():
    parser = optparse.OptionParser("%prog [options] auth|change ...",
                                   description="A win32net.NetValidatePasswordPolicy demo.")

    parser.add_option("-u", "--username",
                      action="store",
                      help="The username to pass to the function (only for the "
                           "change command")

    parser.add_option("-p", "--password",
                      action="store",
                      help="The clear-text password to pass to the function "
                            "(only for the 'change' command)")

    parser.add_option("-m", "--password-matched",
                      action="store_false", default=True,
                      help="Used to specify the password does NOT match (ie, "
                           "uses False for the PasswordMatch/PasswordMatched "
                           "arg, both 'auth' and 'change' commands)")

    parser.add_option("-s", "--server",
                      action="store",
                      help="The name of the server to execute the command on")

    parser.add_option("-f", "--show_fields",
                      action="store_true", default=False,
                      help="Print the NET_VALIDATE_PERSISTED_FIELDS returned")

    options, args = parser.parse_args()

    if not args:
        args = ["auth"]

    for arg in args:
        if arg == "auth":
            input = {"PasswordMatched": options.password_matched,
                     }
            val_type = win32netcon.NetValidateAuthentication
        elif arg == "change":
            input = {"ClearPassword": options.password,
                     "PasswordMatch": options.password_matched,
                     "UserAccountName": options.username,
                     }
            val_type = win32netcon.NetValidatePasswordChange
        else:
            parser.error("Invalid arg - must be 'auth' or 'change'")

        try:
            fields, status = win32net.NetValidatePasswordPolicy(options.server,
                                                         None, val_type, input)
        except NotImplementedError:
            print "NetValidatePasswordPolicy not implemented on this platform."
            return 1
        except win32net.error, exc:
            print "NetValidatePasswordPolicy failed: ", exc
            return 1

        if options.show_fields:
            print "NET_VALIDATE_PERSISTED_FIELDS fields:"
            pprint(fields)

        print "Result of %r validation is %d: %s" % \
                    (arg, status, win32api.FormatMessage(status).strip())

    return 0

if __name__=='__main__':
    sys.exit(main())
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.