Skip to content

Instantly share code, notes, and snippets.

@echiesse
Created June 25, 2017 05:57
Show Gist options
  • Save echiesse/c0ce475df1419ce080b82bb809b70cf3 to your computer and use it in GitHub Desktop.
Save echiesse/c0ce475df1419ce080b82bb809b70cf3 to your computer and use it in GitHub Desktop.
SImple password policy checker.
import string
def minLengthCriterion(minLength):
def f(password):
return len(password) > minLength
return f
def hasCharInGroup(text, group):
ret = False
for c in text:
if c in group:
ret = True
break
return ret
def hasLowerCaseCriterion(password):
return hasCharInGroup(password, string.ascii_lowercase)
def hasUpperCaseCriterion(password):
return hasCharInGroup(password, string.ascii_uppercase)
def hasDigitCriterion(password):
return hasCharInGroup(password, string.digits)
def checkPasswordPolicy(password, criteria):
passed = True
for criterion in criteria:
if not criterion(password):
passed = False
break
return passed
################################################################################
# Example:
password = "abacate1"
criteria = [
minLengthCriterion(6),
hasDigitCriterion,
hasLowerCaseCriterion,
hasUpperCaseCriterion
]
print(checkPasswordPolicy(password, criteria))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment