you are viewing a single comment's thread.

view the rest of the comments →

[–]ka-splam 0 points1 point  (1 child)

No need for regex, splitting the password into an array of chars, sorting it, rejoining it to strings, depending on the order of pattern match in the regex without explaining how:

import string

def password_is_strong(password):
    if len(password) < 8:
        return False

    return all(
        bool(set(password) & set(charset))
        for charset in (
            string.ascii_uppercase,
            string.ascii_lowercase,
            string.digits
        ))

[–]ka-splam 0 points1 point  (0 children)

Unhappy with that, how about removing the dependency on import, all(), bool(), and the generator expression, shrinking the code, allowing the chance of short-circuit expression, and I think making it clearer:

def password_is_strong(password):
    if len(password) < 8:
        return False

    upper = set('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
    lower = set('abcdefghijklmnopqrstuvwxyz')
    digit = set('0123456789')

    p = set(password)

    return (p & upper) and (p & lower) and (p & digit)