From: Steven Tobin Date: Fri, 14 Jun 2013 01:16:18 +0000 (+0100) Subject: change non-interactive code to return passwd X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=67daedc5f6928e48d0a19be1d70c90ae081f14ad;p=redacted-XKCD-password-generator.git change non-interactive code to return passwd --- diff --git a/xkcd_password.py b/xkcd_password.py index 3f99bf3..7b6b99b 100755 --- a/xkcd_password.py +++ b/xkcd_password.py @@ -137,7 +137,7 @@ def verbose_reports(length, numwords, wordfile): print("The supplied word list is located at %s." % os.path.abspath(wordfile)) - if (int(bits) == bits): + if int(bits) == bits: print("Your word list contains %i words, or 2^%i words." % (length, bits)) else: @@ -175,6 +175,8 @@ def generate_xkcdpassword(wordlist, Generate an XKCD-style password from the words in wordlist. """ + passwd = False + if len(wordlist) < n_words: sys.stderr.write("Could not get enough words!\n" "This could be a result of either your wordfile\n" @@ -184,9 +186,11 @@ def generate_xkcdpassword(wordlist, # useful if driving the logic from other code if not interactive: if not acrostic: - return delim.join(rng().sample(wordlist, n_words)) + passwd = delim.join(rng().sample(wordlist, n_words)) else: - return delim.join(find_acrostic(acrostic, wordlist)) + passwd = delim.join(find_acrostic(acrostic, wordlist)) + + return passwd # else, interactive session if not acrostic: