Handle min > max case
authorSteven Tobin <steventtobin (at) gmail.com>
Tue, 5 Sep 2017 21:47:04 +0000 (22:47 +0100)
committerSteven Tobin <steventtobin (at) gmail.com>
Tue, 5 Sep 2017 21:47:04 +0000 (22:47 +0100)
xkcdpass/xkcd_password.py

index edb4353144341366ef6d40e6b61b187bd92b79a0..c65846210c18cda8ae39864e7bbb484bae5c6858 100755 (executable)
@@ -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:
git clone https://git.99rst.org/PROJECT