Skip to content

Instantly share code, notes, and snippets.

@kotas
Created January 4, 2012 08:22

Revisions

  1. kotas created this gist Jan 4, 2012.
    35 changes: 35 additions & 0 deletions genpass.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #!/usr/bin/python
    # -*- encoding: utf-8 -*-
    """
    Password Generator for Mac OSX
    Compatible with http://www.hashapass.com/
    """

    import sys
    import os
    import hmac
    import hashlib
    import base64

    os.system("stty -echo >/dev/null 2>&1")
    try:
    sys.stdout.write("Type master: ")
    master = sys.stdin.readline().rstrip()
    sys.stdout.write("\r" + " " * 80 + "\r")

    sys.stdout.write("Type parameter: ")
    parameter = sys.stdin.readline().rstrip()
    sys.stdout.write("\r" + " " * 80 + "\r")

    gen = hmac.new(master, parameter, hashlib.sha1)
    password = base64.b64encode(gen.digest())
    password = password[0:8]

    clipboard = os.popen("pbcopy", "w")
    clipboard.write(password)
    clipboard.close()

    sys.stdout.write("Password is set to clipboard.\n")
    finally:
    os.system("stty echo >/dev/null 2>&1")