Created
June 25, 2017 05:57
-
-
Save echiesse/c0ce475df1419ce080b82bb809b70cf3 to your computer and use it in GitHub Desktop.
SImple password policy checker.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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