[Tutor] function with multiple checks

Steven D'Aprano steve at pearwood.info
Mon Sep 27 19:34:35 CEST 2010


On Tue, 28 Sep 2010 01:09:54 am Tim Miller wrote:

> def complex_password(password):
>      """Checks password for sufficient complexity."""
>      if len(password) < 12:
>          return False
>      if len([c for c in password if c in punctuation]) == 0:
>          return False
>      if len([c for c in password if c in digits]) == 0:
>          return False
>      if len([c for c in password if c in ascii_uppercase]) == 0:
>          return False
>      if len([c for c in password if c in ascii_lowercase]) == 0:
>          return False
>      return True

def complex_password(password):
    return ( 
    len(password) >= 12 and
    any(c in punctuation for c in password) and
    any(c in digits for c in password) and
    any(c in ascii_uppercase for c in password) and
    any(c in ascii_lowercase for c in password)
    )



-- 
Steven D'Aprano


More information about the Tutor mailing list