Skip to main content

Section 3.12 Unit 3 Procedures Project

45 minutes
The Password Checker project was designed by Leigh Anne Fitz of Virginia Beach City Public Schools and the autograding tests were designed by Kate McDonnell of Cherry Creek Schools in Colorado.

Subsection 3.12.1 Password Checker

A strong password typically meets the following criteria:
  • Is at least 12 characters
  • Contains uppercase and lowercase letters
  • Contains numbers
  • Contains special characters: ~`!@#$%^&*() _-+={[}]|\\:;\"\'>,<.?/
Create a Python program that determines whether a user’s password is strong or weak. The program should prompt the user to enter their password, then determine whether it meets all requirements. It will then print whether the password is β€œStrong” or β€œWeak.”
Program Requirements
  • Define a function check_password with a single parameter that is the user’s password:
    • Check the length of the password. If it is shorter than 12 characters:
      • Print β€œYour password is not long enough.”
      • Do not complete the other checks if the password is too short
    • Create boolean variables for upper, lower, number, and special
    • Loop through each letter in the password:
      • If it is uppercase, set upper to true
      • If it is lowercase, set lower to true
      • If it is a number, set number to true
      • If it is a special character, set special to true
    • Print the results of the requirements that are not met:
      • β€œYour password does not contain any numbers.”
      • β€œYour password does not contain any uppercase letters.”
      • β€œYour password does not contain any lowercase letters.”
      • β€œYour password does not contain any special characters.”
    • If all four boolean values are true, print β€œYour password is strong”
  • After (and outside) the function:
    • Prompt the user to enter a password
    • Call the check_password function with the user’s password as an argument
Table 3.12.1. Password Validation Requirements and Outputs
Input Output
Password12! Your password is not long enough.
abcdefghijkl
Your password does not contain any numbers.
Your password does not contain any uppercase letters.
Your password does not contain any special characters.
ABCDEFJGHIJLKL123! Your password does not contain any lowercase letters.
SecurePassword! Your password does not contain any numbers.
SecurePass123! Your password is strong.
Use the following string methods to check each character in your password:
  • letter.isupper() - returns True if the letter is uppercase
  • letter.islower() - returns True if the letter is lowercase
  • letter.isdigit() - returns True if the letter is a number
  • letter.isalnum() - returns True if the letter is a letter or number, False if it is a special character

Project 3.12.1 Password Checker.

Create a Python program that determines whether a user’s password is strong or weak. The program should prompt the user to enter their password, then determine whether it meets all requirements. It will then print whether the password is β€œStrong” or β€œWeak.”
Use the directions in the β€œProgram Requirements” section to create your program.

Subsection 3.12.2 Project Reflection

Activity 3.12.2 Project Reflection: Procedure.

Consider the procedure (check_password()) you wrote for this project. Write two calls to your procedure that each cause a different code segment in the procedure to execute. Describe the expected behavior of each call. If it is not possible for two calls to your procedure to cause different code segments to execute, explain why this is the case for your procedure.

Activity 3.12.3 Project Reflection: Procedure.

Consider the procedure (check_password()) you wrote for this project. Suppose another programmer modifies the code within this procedure. Describe a modification the other programmer could make that would cause this procedure to have a logic error. Describe how the behavior of this procedure would change because of the error.

Activity 3.12.4 Project Reflection: Errors.

Describe an error that you encountered while you were creating the code, and how you fixed your code to remove the bug. How did you test the code to make sure it was working correctly?
You have attempted of activities on this page.