# Python 3 compatibility
if sys.version_info[0] >= 3:
raw_input = input
+ xrange = range
def validate_options(parser, options, args):
return words
+def choose_words(wordlist, numwords):
+ s = []
+ for i in xrange(numwords):
+ s.append(rng().choice(wordlist))
+ return s
+
def generate_xkcdpassword(wordlist,
numwords=6,
interactive=False,
passwd = False
- if len(wordlist) < numwords:
- sys.stderr.write("Could not get enough words!\n"
- "This could be a result of either your wordfile\n"
- "being too small, or your settings too strict.\n")
- sys.exit(1)
-
# generate the worddict if we are looking for acrostics
if acrostic:
worddict = wordlist_to_worddict(wordlist)
# useful if driving the logic from other code
if not interactive:
if not acrostic:
- passwd = delimiter.join(rng().sample(wordlist, numwords))
+ passwd = delimiter.join(choose_words(wordlist, numwords))
else:
passwd = delimiter.join(find_acrostic(acrostic, worddict))
while accepted.lower() not in ["y", "yes"]:
if not acrostic:
- passwd = delimiter.join(rng().sample(wordlist, numwords))
+ passwd = delimiter.join(choose_words(wordlist, numwords))
else:
passwd = delimiter.join(find_acrostic(acrostic, worddict))
print("Generated: ", passwd)