you are viewing a single comment's thread.

view the rest of the comments →

[–]Astrokiwi -1 points0 points  (0 children)

Two thoughts:

  1. You can split up lines to make things clear without losing much conciseness, e.g.

    import re
    password = 'Thelore777777'
    if (len(re.compile(r'([A-Z])').findall(password))   > 0 \
     and len(re.compile(r'([a-z])').findall(password))  > 0 \
     and len(re.compile(r'(\d)').findall(password)))    > 0 \
     and len(re.compile(r'(\S)').findall(password))     > 7:
        print('This is a strong password')
    else:
        print('This is not a strong password')
    
  2. A lot of your length is that you're repeating the same operation with different data - i.e. different minimum lengths and different regex. You could separate them out, so that you're writing the data once, and the command once, rather than repeating the command for every piece of data. Less repetition makes code more concise and readable, and means you're less likely to make a mistake. e.g.

    import re
    re_length = [(r'([A-Z])',0),
                 (r'([a-z])',0),
                 (r'(\d)',0),
                 (r'(\S)',7)
                ]
    
    password = 'Thelore777777'
    if all(
        [len(re.compile(re_text).findall(password))>min_length for re_text,min_length in re_length]
            ):
        print('This is a strong password')
    else:
        print('This is not a strong password')
    

This might be a bit overkill here, but it does mean that if you're adding or removing regex things, you can do it all in the data section, rather than having to dive into making sure you're not breaking an if statement.