Created
October 3, 2011 14:22
-
-
Save cspickert/1259200 to your computer and use it in GitHub Desktop.
An implementation of the Oplop password hashing algorithm in Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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