Last active
December 18, 2015 01:29
-
-
Save drscream/5704329 to your computer and use it in GitHub Desktop.
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, string, random, sys, getpass | |
def gen_salt(): | |
letters=string.ascii_letters+string.digits # alphanumeric, upper and lowercase | |
return ''.join([random.choice(letters) for _ in range(8)]) | |
if len(sys.argv) < 1: | |
print "Usage: %s [salt]" % (sys.argv[0]) | |
sys.exit() | |
if len(sys.argv) > 1: | |
salt = sys.argv[1] | |
else: | |
salt = gen_salt() | |
pprompt = lambda: (getpass.getpass(), getpass.getpass('Retype password: ')) | |
p1, p2 = pprompt() | |
while p1 != p2: | |
print('Passwords do not match. Try again') | |
p1, p2 = pprompt() | |
print crypt.crypt(p1, '$1$' + salt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment