From: Stanislav Bytsko Date: Tue, 11 Jun 2013 08:59:40 +0000 (+0300) Subject: Add option to have custom word delimiters X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=6ea70853568445f5924f14b464d6c8c11c41a542;p=redacted-XKCD-password-generator.git Add option to have custom word delimiters --- diff --git a/xkcd_password.py b/xkcd_password.py index b201734..de4cd65 100755 --- a/xkcd_password.py +++ b/xkcd_password.py @@ -97,7 +97,7 @@ def validate_options(options, args): sys.stderr.write("Could not find a word file, or word file does " "not exist.\n") sys.exit(1) - + def generate_wordlist(wordfile=None, min_length=5, @@ -161,7 +161,7 @@ def find_acrostic(acrostic, wordlist): while 1: word = rng().choice(wordlist) if word[0] == letter: - words += word + " " + words += word + options.delim break return words @@ -183,7 +183,7 @@ def generate_xkcdpassword(wordlist, # useful if driving the logic from other code if not interactive: if not acrostic: - return " ".join(rng().sample(wordlist, n_words)) + return options.delim.join(rng().sample(wordlist, n_words)) else: return find_acrostic(acrostic, wordlist) @@ -200,7 +200,7 @@ def generate_xkcdpassword(wordlist, while accepted.lower() not in ["y", "yes"]: if not acrostic: - passwd = " ".join(rng().sample(wordlist, n_words)) + passwd = options.delim.join(rng().sample(wordlist, n_words)) else: passwd = find_acrostic(acrostic, wordlist) print("Generated: ", passwd) @@ -242,6 +242,8 @@ if __name__ == '__main__': parser.add_option("-c", "--count", dest="count", default=1, type="int", help="number of passwords to generate") + parser.add_option("-d", "--delimiter", dest="delim", + default=" ", help="separator character between words") (options, args) = parser.parse_args() validate_options(options, args)