Created
September 1, 2016 08:18
-
-
Save bacher09/24790188a2ed2c613fe8dc0ae38056aa to your computer and use it in GitHub Desktop.
This file contains 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 python3 | |
import getpass | |
import crypt | |
import argparse | |
import sys | |
METHODS_DICT = dict((meth.name.lower(), meth) for meth in crypt.methods) | |
parser = argparse.ArgumentParser(description="Hash generator") | |
parser.add_argument( | |
'-p', '--password', | |
help="Get password from CLI args", | |
type=str, dest='password' | |
) | |
parser.add_argument( | |
'-m', '--method', | |
help="Crypt method", | |
type=str, | |
choices=METHODS_DICT.keys(), | |
dest='method', | |
default='sha512' | |
) | |
def read_password(): | |
password = getpass.getpass() | |
same_password = getpass.getpass("Password again: ") | |
if password == same_password: | |
return password | |
else: | |
return None | |
def main(): | |
args = parser.parse_args() | |
crypt_method = METHODS_DICT[args.method] | |
if args.password is None: | |
pwd = read_password() | |
if pwd is None: | |
print("Passwords isn't match, please try again") | |
sys.exit(1) | |
else: | |
pwd = args.password | |
print("hash is: ", crypt.crypt(pwd, crypt_method)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment