From: Steven Tobin Date: Tue, 5 Sep 2017 21:47:04 +0000 (+0100) Subject: Handle min > max case X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=c53bab9564e20f38c89d5b572fc1977b8a2edaf3;p=redacted-XKCD-password-generator.git Handle min > max case --- diff --git a/xkcdpass/xkcd_password.py b/xkcdpass/xkcd_password.py index edb4353..c658462 100755 --- a/xkcdpass/xkcd_password.py +++ b/xkcdpass/xkcd_password.py @@ -66,10 +66,9 @@ def validate_options(parser, options): """ if options.max_length < options.min_length: - sys.stderr.write("The maximum length of a word can not be " - "less than the minimum length.\n" - "Check the specified settings.\n") - sys.exit(1) + sys.stderr.write("Warning: maximum word length less than minimum. " + "Setting maximum equal to minimum.\n") + # sys.exit(1) wordfile = locate_wordfile(options.wordfile) if not wordfile: @@ -113,7 +112,10 @@ def generate_wordlist(wordfile=None, Generate a word list from either a kwarg wordfile, or a system default valid_chars is a regular expression match condition (default - all chars) """ - + + # deal with inconsistent min and max, erring toward security + if min_length > max_length: + max_length = min_length wordfile = locate_wordfile(wordfile) words = [] @@ -121,7 +123,6 @@ def generate_wordlist(wordfile=None, regexp = re.compile("^{0}{{{1},{2}}}$".format(valid_chars, min_length, max_length)) - # read words from file into wordlist with open(wordfile) as wlf: for line in wlf: