Skip to content

Instantly share code, notes, and snippets.

@kotas
Created January 4, 2012 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kotas/1559083 to your computer and use it in GitHub Desktop.
Save kotas/1559083 to your computer and use it in GitHub Desktop.
Password Generator for Mac OSX
#!/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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment