Permalink
Cannot retrieve contributors at this time
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?
6005CEM-Security-CW2/password-strength-checker.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42 lines (30 sloc)
2.1 KB
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 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 |