From: Steven Tobin Date: Tue, 20 Sep 2011 14:37:50 +0000 (+0100) Subject: Initial commit X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=ee0559e4fdcf847f16561dc6e8dd0330f091ece9;p=redacted-XKCD-password-generator.git Initial commit --- ee0559e4fdcf847f16561dc6e8dd0330f091ece9 diff --git a/README.mkd b/README.mkd new file mode 100644 index 0000000..07b2764 --- /dev/null +++ b/README.mkd @@ -0,0 +1,7 @@ +A simple command line script that generates XKCD-style multiword passwords + +See http://xkcd.com/936/ + +**Configuration:** Change `word_list` variable in `generate_wordlist()` + +**Requirements:** None diff --git a/xkcd-password.py b/xkcd-password.py new file mode 100755 index 0000000..d2f56c4 --- /dev/null +++ b/xkcd-password.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# encoding: utf-8 + +import random +import os + +def generate_wordlist(min_length=5, max_length=9): + ## OS X + # word_list = "/usr/share/dict/words" + ## Linux + # word_list = "/usr/dict/words" + ## Downloaded || custom + word_list = os.path.expanduser("~/local/share/dict/common") + + words = [] + + try: + with open(word_list) as wlf: + for line in wlf: + if min_length <= len(line.strip()) <= max_length: + words.append(line.strip()) + except: + ## file not found + pass + + return words + +if __name__ == '__main__': + n_words = raw_input("Enter number of words (default 4): ") + if not n_words: n_words = 4 + + accepted = "n" + wordlist = generate_wordlist() + + while accepted.lower() not in [ "y", "yes" ]: + passwd = " ".join(random.sample(wordlist, n_words)) + print "Generated: ", passwd + accepted = raw_input("Accept? [yN] ") + +