alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
uppercase_alphabet = ['A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
symbols = ["!", "@", "#", "$", "%", "^", "&", "*",
"(", ")", "_", "+", "-", "=", "?", ",", ".", ":", ";",
"\\", "|", "<", ">", "/", "{", "}", "[", "]"]
common_words = ["password", "dog", "cat", "pet", "pw", "hello",
"secret", "codesters", "school", "123"]
main_text = codesters.Text("Your password must contain the following:", 0, 215)
rule_1 = codesters.Text("An uppercase letter (A-Z)", 0, 175)
rule_2 = codesters.Text("A lowercase letter (a-z)", 0, 150)
rule_3 = codesters.Text("A number (0-9)", 0, 125)
rule_4 = codesters.Text("A symbol (such as !, #, or %)", 0, 100)
rule_5 = codesters.Text("Ten or more characters total", 0, 75)
password = stage.ask("Enter a password to check:")
password_score = 0
# Lower case letter check
lower_case = False
for char in password:
if char in alphabet:
lower_case = True
password_score += 1
# Upper case letter check
upper_case = False
for char in password:
if char in uppercase_alphabet:
upper_case = True
password_score += 2
# Number check
number = False
for char in password:
if char in numbers:
number = True
password_score += 4
# Symbol check
symbol = False
for char in symbols:
if char in password:
symbol = True
password_score += 5
# Common word check
for word in common_words:
if word in password.lower():
password_score -= len(word) + 15
excludes_password = False
if "password" not in password.lower():
excludes_password = True
# Length check
password_length = len(password)
length = False
if password_length >= 10:
length = True
if password_length > 10 and password_length <= 12:
password_score += 10
elif password_length > 12 and password_length <= 15:
password_score += 20
elif password_length > 15:
password_score += 40
stage.set_color("blue")
result = codesters.Text("Your password is: ")
if password_score < 0:
stage.set_background_color("red")
strength = "extremely weak"
elif password_score >= 0 and password_score <= 10:
stage.set_background_color("orangered")
strength = "very weak"
elif password_score > 10 and password_score <= 25:
stage.set_background_color("orange")
strength = "weak"
elif password_score > 25 and password_score <= 50:
stage.set_background_color("yellow")
strength = "okay"
elif password_score > 50 and password_score <= 75:
stage.set_background_color("greenyellow")
strength = "strong"
elif password_score > 75 and password_score <= 100:
stage.set_background_color("limegreen")
strength = "very strong"
elif password_score > 100:
stage.set_background_color("green")
strength = "extremely strong"
if lower_case and upper_case and number and symbol and excludes_password and length:
result.set_text("Your password is: " + strength)
else:
stage.set_background_color("red")
result.set_text("Your password is: invalid")
print(password)
print(password_score)