This repository was archived by the owner on Oct 20, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy path09_CodeExample_PasswordChecker.py
More file actions
76 lines (55 loc) · 2.36 KB
/
Copy path09_CodeExample_PasswordChecker.py
File metadata and controls
76 lines (55 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
password = input("Enter a new password:")
result = [] # create a blank list to store our checks for each of the 3 conditions of a strong password:
# A strong password should:
# 1) Be at least 8 characters long
# 2) Have at least 3 numeric digits
# 3) Have at least one upper and one lower case character
if len(password) >= 8:
result.append(True)
# check if each character of password is a digit, and we have at least 3 digits:
digit = False
digits = []
for i in password:
if i.isdigit():
digit = True
digits.append(digit)
print(f"Your password contains {sum(digits)} numbers.")
if sum(digits) >= 3:
result.append(True)
else:
result.append(False)
# Check if we have at least one uppercase and one lowercase character
uppercase = False
uppers = []
for i in password:
if i.isupper():
uppercase = True
uppers.append(uppercase)
print(f"Your password contains {sum(uppers)} uppercase characters.")
lowercase = False
lowers = []
for i in password:
if i.islower():
lowercase = True
lowers.append(lowercase)
print(f"Your password contains {sum(lowers)} lowercase characters.")
if sum(lowers) >= 1 and sum(uppers) >= 1:
result.append(True)
else:
result.append(False)
print(f"Your password passes {sum(result)} of the 3 criterion tests.")
print(result)
# if sum(result) == 3:
# print("You have entered a Strong Password.")
# else:
# print("You have entered a Weak Password.")
if all(result): # returns as True IFF every boolean in the containment unit is True.
print("You have entered a Strong Password.")
else:
print("You have entered a Weak Password.")
# Now let's rewrite all this code using a DICTIONARY for result instead of a LIST.
# Complication: the method .append() does NOT exist for Dictionaries. SO:
#################################################################################################################################################
#################################################################################################################################################
#################################################################################################################################################
#################################################################################################################################################