Skip to content

Instantly share code, notes, and snippets.



Last active Mar 30, 2016
What would you like to do?
Unique, reproducible per-domain password generation.
#!/usr/bin/env python
## Imports
import base64
import hashlib
import argparse
from getpass import getpass
## Module Constants
VERSION = " 1.0"
DESCRIPTION = "Generates unique, long, reproducible passwords."
EPILOG = "See for more information."
def get_password(attempts=0):
password = getpass("Enter master passphrase: ").strip()
confirm = getpass("Enter same passphrase again: ").strip()
if password != confirm:
if attempts < 3:
print "Passwords do not match, try again."
return get_password(attempts+1)
raise Exception("Password attempt maximum, stretch fingers and try again!")
if not password:
raise Exception("You must supply a base password for the generator!")
return password
def main(args):
Use raw input to collect information from the command line.
# Create the base password string
password = "{}{}{}".format(args.domain[0], args.salt, get_password())
# Hash and encode the base password
password = base64.b64encode(hashlib.sha256(password).digest())
return password
if __name__ == "__main__":
parser = argparse.ArgumentParser(
version=VERSION, description=DESCRIPTION, epilog=EPILOG,
# Create the arguments
'-s', '--salt', default='', type=str,
help='salt or increment to add to password',
'domain', nargs=1,
help='the domain of the site to generate a password for',
# Parse the arguments
args = parser.parse_args()
# Execute the script
result = main(args)
if result:
except Exception as e:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment