Skip to content

Instantly share code, notes, and snippets.

@cspickert
Created October 3, 2011 14: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 cspickert/1259200 to your computer and use it in GitHub Desktop.
Save cspickert/1259200 to your computer and use it in GitHub Desktop.
An implementation of the Oplop password hashing algorithm in Python.
#!/usr/bin/env python
"""Generate a password using the Oplop password hashing algorithm.
For more information: http://code.google.com/p/oplop/wiki/HowItWorks"""
from sys import argv, stdout
from hashlib import md5
from base64 import urlsafe_b64encode as b64
import re
PASS_LEN = 8
DIGIT_RE = re.compile('\d+')
def oplop(nickname, master_password, pass_len=PASS_LEN):
hashed = b64(md5(master_password + nickname).digest())
digits = DIGIT_RE.findall(hashed[:pass_len])
if not digits:
digits = DIGIT_RE.findall(hashed)
hashed = (digits and digits[0] or '1') + hashed
return hashed[:pass_len]
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('nickname', help='Account nickname')
parser.add_argument('master_password', help='Master password')
args = parser.parse_args()
stdout.write(oplop(args.nickname, args.master_password))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment