Created
November 4, 2013 10:45
-
-
Save arnobroekhof/7300924 to your computer and use it in GitHub Desktop.
Generate crypt ( passwd compliant ) sha512 password with python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import crypt | |
| import string | |
| import random | |
| import sys | |
| from optparse import OptionParser | |
| def salt_generator(size=20, chars=string.ascii_uppercase + string.digits): | |
| return ''.join(random.choice(chars) for x in range(size)) | |
| usage = "usage: %prog [options] arg1 arg2" | |
| parser = OptionParser(usage=usage) | |
| parser.add_option("-p", "--password", dest="passwd", | |
| help="Password to encrypt", metavar="<password>") | |
| parser.add_option("-s", "--salt", dest="salt", | |
| help="salt to use ( if not specified it's generated", metavar="<salt>") | |
| (options,args) = parser.parse_args() | |
| if not options.passwd: | |
| parser.error('No password given') | |
| if not options.salt: | |
| options.salt = salt_generator() | |
| print crypt.crypt(options.passwd, "$6$%s" % options.salt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment