More secure rand. num generator, fixed input error, clearer error msgs.
authorMithrandirAgain <redacted>
Sat, 24 Sep 2011 00:00:28 +0000 (17:00 -0700)
committerMithrandirAgain <redacted>
Sat, 24 Sep 2011 00:00:28 +0000 (17:00 -0700)
README.mkd
xkcd-password.py

index 1760dd1df2a65aeb836042bfdc024d14d5ef7617..c90fb221a17f6755699a16361d80020bde8a144b 100644 (file)
@@ -6,4 +6,4 @@ For more memorable words, try `2of12.txt`, available from http://wordlist.source
 
 **Configuration:** Change `word_list` variable in `generate_wordlist()` 
 
-**Requirements:** None
+**Requirements:** Python 2.4+
index d2f56c49df609d92a4b970b9ba276681c56a6229..4091e9642a0edef0df7ebab3cb6d722247a30033 100755 (executable)
@@ -20,20 +20,23 @@ def generate_wordlist(min_length=5, max_length=9):
                 if min_length <= len(line.strip()) <= max_length:
                     words.append(line.strip())
     except:
-        ## file not found
-            pass
-
+            print 'File not found.'
+            raise SystemExit
     return words
 
 if __name__ == '__main__':
     n_words = raw_input("Enter number of words (default 4): ")
     if not n_words: n_words = 4
-
+    else: n_words = int(n_words)
+    
     accepted = "n"
     wordlist = generate_wordlist()
 
     while accepted.lower() not in [ "y", "yes" ]:
-        passwd = " ".join(random.sample(wordlist, n_words))
+        try:
+            passwd = " ".join(random.SystemRandom().sample(wordlist, n_words))
+        except NotImplementedError:
+            print 'System does not support random number generator or Python version < 2.4.'
         print "Generated: ", passwd
         accepted = raw_input("Accept? [yN] ")
 
git clone https://git.99rst.org/PROJECT