Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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