Password
Password
Passwords
A network technician has set the following rules for passwords on their network:
● It has at least 8 characters
● It contains both upper case and lower case letters
● It contains at least one numeric digit
● It contains at least one symbol
So, a password like pyth0n would not be considered safe, whereas Pyth0n!stAs would.
Task 1 . Is it safe?
Create a Python program that prompts the user to enter a password and displays whether or not the
password follows the technician’s rules. .
Example
Note: Use this example to check your program. This is the output your program should produce for the given input.
The program displays a message that pyth0n is not considered a safe password:
the password is not safe
Example
Note: Use this example to check your program. This is the output your program should produce for the given input.
Page 1
Year 9 – Python programming with sequences of data Activity handout
Computes whether or not the password contains any lower case characters OR computes
✔
how many lower case letters the password contains.
Computes whether or not the password contains any upper case characters OR computes
✔ how many upper case letters the password contains.
Computes whether or not the password contains any digits OR computes how many digits
✔
the password contains.
Computes whether or not the password contains any symbols OR computes how many
✔ symbols the password contains.
Displays a message informing the user whether or not the password provided meets the
✔
network criteria.
import random
Page 2
Year 9 – Python programming with sequences of data Activity handout
lowercase = 'abcdefghijklmnopqrstuvwxyz'
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits = '0123456789'
symbols = '!,#,$,%,&,(),*,+,-,.,/,:,;,<,=,>,?,@,[,\,],^,_,`,{,|,},~'
length = len(password)
lowercase_count = 0
uppercase_count = 0
digit_count = 0
symbol_count = 0
if length < 8:
print(password , " is not considered a safe password.")
elif lowercase_count == 0 or uppercase_count == 0 or digit_count == 0 or symbol_count
== 0:
print(password , " is not considered a safe password.")
else:
print(password , " is considered a safe password.")
Example
Note: Use this example to check your program. This is the output your program should produce for the given input.
meet No symbols
Displays the individual safety criteria that are not met by the provided password (see
✔
example).
import random
lowercase = 'abcdefghijklmnopqrstuvwxyz'
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits = '0123456789'
symbols = '!,#,$,%,&,(),*,+,-,.,/,:,;,<,=,>,?,@,[,\,],^,_,`,{,|,},~'
password = input("Enter a password: ")
length = len(password)
lowercase_count = 0
uppercase_count = 0
digit_count = 0
symbol_count = 0
criteria = []
if length < 8:
criteria.append("Less than 8 characters")
if lowercase_count == 0:
criteria.append("No lowercase letters")
if uppercase_count == 0:
criteria.append("No uppercase letters")
if digit_count == 0:
criteria.append("No digits")
if symbol_count == 0:
criteria.append("No symbols")
Page 4
Year 9 – Python programming with sequences of data Activity handout
if criteria:
print("The password does not meet the following criteria:")
for criterion in criteria:
print(criterion)
else:
print(password, "is considered a safe password.")
counter = counter + 1
This statement can be read as ‘increase the counter by 1’. Don’t forget to initialise each counter to
zero.
Page 5
Year 9 – Python programming with sequences of data Activity handout
character in text
The strings below will come in handy (copy and paste them in your code), for checking where each
individual character in the password belongs:
lowercase = 'abcdefghijklmnopqrstuvwxyz'
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits = '0123456789'
symbols = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
password = "".join(characters)
Page 6