Initial commit
authorSteven Tobin <tobin2402 (at) gmail.com>
Tue, 20 Sep 2011 14:37:50 +0000 (15:37 +0100)
committerSteven Tobin <tobin2402 (at) gmail.com>
Tue, 20 Sep 2011 14:41:18 +0000 (15:41 +0100)
README.mkd [new file with mode: 0644]
xkcd-password.py [new file with mode: 0755]

diff --git a/README.mkd b/README.mkd
new file mode 100644 (file)
index 0000000..07b2764
--- /dev/null
@@ -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 (executable)
index 0000000..d2f56c4
--- /dev/null
@@ -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] ")
+
+
git clone https://git.99rst.org/PROJECT