Created
September 10, 2013 17:56
-
-
Save tkhn/6513072 to your computer and use it in GitHub Desktop.
Simple console htpasswd hash generator
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/python | |
| """Replacement for htpasswd""" | |
| # Original author: Eli Carter | |
| # Inspired by https://gist.github.com/eculver/1420227 | |
| import crypt | |
| import os | |
| import sys | |
| import random | |
| from optparse import OptionParser | |
| def salt(): | |
| """Returns a string of 2 randome letters""" | |
| letters = 'abcdefghijklmnopqrstuvwxyz' \ | |
| 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' \ | |
| '0123456789/.' | |
| return random.choice(letters) + random.choice(letters) | |
| def main(): | |
| """%prog username password | |
| Generate passwd hash""" | |
| parser = OptionParser(usage=main.__doc__) | |
| options, args = parser.parse_args() | |
| # Non-option arguments | |
| if len(args) != 2: | |
| syntax_error("Insufficient number of arguments.\n") | |
| else: | |
| username = args[0] | |
| password = args[1] | |
| print "{0}:{1}".format(username, crypt.crypt(password, salt())) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment