Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import re #imports regular expressions
def checkPassword(password): #checks to see if password meets the requirements
requirements = { #defines the requirements for the password
"length" : 8,
"lowers" : 1,
"uppers" : 1,
"numbers" : 1,
"symbols" : 1
}
checks = {}
checks["lenth"] = len(password) >= requirements["length"] #checks to see if the password is long enough
checks["lowers"] = re.search(r"[a-z]", password) is not None #checks to see if the password contains lower case characters
checks["uppers"] = re.search(r"[A-Z]", password) is not None #checks to see if the password contains upper case characters
checks["numbers"] = re.search(r"\d", password) is not None #checks to see if the password contains numbers
checks["symbols"] = re.search(r"[ !#$%&'()*+,-./[\\\]^_`{|}~"+r'"]', password) is not None #checks to see if the password contains symbols
overall_strength = 0
for key in checks.keys(): #loops through all the checks
if checks[key]: #checks to see if the check has been passed
overall_strength += 1 #totals up the number of passed checks
print(overall_strength)
match overall_strength: #checks the strength of the password
case overall_strength if overall_strength in [0, 1, 2]: #if the password passes < 3 checks, its deemed weak
checks["strength"] = "weak"
case overall_strength if overall_strength in [3, 4]: #if the password passes < 5 checks, its deemed moderate
checks["strength"] = "moderate"
case 5: #if the password passes all checks, its deemed strong
checks["strength"] = "strong"
return checks
password = input("please enter the password: ") #takes the users password input
print(checkPassword(password)) #outputs the checks on the password