๐ŸŽ‰ Welcome to PyVerse! Start Learning Today

Password Strength Checker using Regular Expressions

Intermediate

Build a real-time password security analyzer with Python

1) Project Overview

The Password Strength Checker helps users create strong and secure passwords by analyzing their password's structure and providing instant feedback.

This program uses regular expressions (regex) to evaluate if a password:

  • Contains uppercase and lowercase letters
  • Has at least one digit
  • Includes a special character
  • Meets a minimum length requirement

๐Ÿ’ก Why it's useful: Weak passwords are a common cause of data breaches. This tool teaches users to understand password security and helps developers implement real-time validation in registration systems.

2) Learning Objectives

By completing this project, students will:

  • ๐Ÿง  Understand Regular Expressions (re module) and pattern matching
  • ๐Ÿงฉ Learn string validation using multiple conditions
  • ๐Ÿ’ฌ Practice user input handling and formatted output
  • ๐Ÿ”„ Use functions for modular and reusable code
  • ๐Ÿ“ˆ Learn how to rate password strength dynamically (weak, medium, strong)

3) Step-by-Step Explanation

Follow these steps to build the password checker:

  1. Import the Required Library โ€“ Python's built-in re (Regular Expressions) library helps us define complex validation patterns easily
  2. Create the Password Validation Function โ€“ We'll define check_password_strength(password) to test the password against several regex patterns, calculate how many conditions it passes, and return a message indicating whether it's weak, medium, or strong
  3. Define Validation Criteria โ€“ We'll check for:
    • Minimum length (8 characters)
    • At least one uppercase letter
    • At least one lowercase letter
    • At least one digit
    • At least one special symbol (@, #, $, %, &, *, etc.)
  4. Use Regex Patterns โ€“ Examples: [A-Z] โ†’ Uppercase letters, [a-z] โ†’ Lowercase letters, [0-9] โ†’ Digits, [@#$%^&*()_+=!~] โ†’ Special characters
  5. Display the Result โ€“ Use conditional logic to classify: Weak โ†’ Less than 3 conditions met, Medium โ†’ 3โ€“4 conditions met, Strong โ†’ All conditions met

4) Complete, Well-Commented, and Verified Python Code

You can copy this into a file named password_checker.py and run it.

# --------------------------------------------------- # ๐Ÿ” Password Strength Checker using Regular Expressions # --------------------------------------------------- # Author: Your Name # Level: Intermediate # Verified with Python 3.8+ # --------------------------------------------------- import re def check_password_strength(password): """Evaluates and returns the strength of a password.""" # Initialize score score = 0 # Criteria 1: Length at least 8 if len(password) >= 8: score += 1 # Criteria 2: Contains uppercase letter if re.search(r"[A-Z]", password): score += 1 # Criteria 3: Contains lowercase letter if re.search(r"[a-z]", password): score += 1 # Criteria 4: Contains a digit if re.search(r"[0-9]", password): score += 1 # Criteria 5: Contains special character if re.search(r"[@#$%^&*()_+=!~]", password): score += 1 # Determine strength if score <= 2: strength = "Weak ๐Ÿ”ด" elif score == 3 or score == 4: strength = "Medium ๐ŸŸก" else: strength = "Strong ๐ŸŸข" return strength # -------------------------- # Main Program Execution # -------------------------- if __name__ == "__main__": print("๐Ÿ” Password Strength Checker") print("-" * 35) # Get password input from user user_password = input("Enter your password: ") # Check strength result = check_password_strength(user_password) # Display result print(f"\nPassword Strength: {result}") # Suggest improvement if weak if "Weak" in result: print("โ— Tip: Use uppercase, lowercase, digits, and symbols to make it stronger.") elif "Medium" in result: print("โš ๏ธ Almost there! Add more variety (special chars or numbers).") else: print("โœ… Excellent! Your password is strong and secure.")

โœ… Verified: Tested in Python 3.8 and 3.11 โ€” runs perfectly with no errors.
โœ… Libraries Used: Only re (built-in).

5) Sample Output

Example 1: Weak Password

๐Ÿ” Password Strength Checker
-----------------------------------
Enter your password: hello

Password Strength: Weak ๐Ÿ”ด
โ— Tip: Use uppercase, lowercase, digits, and symbols to make it stronger.

Example 2: Medium Password

Enter your password: Hello123

Password Strength: Medium ๐ŸŸก
โš ๏ธ Almost there! Add more variety (special chars or numbers).

Example 3: Strong Password

Enter your password: Hello@123

Password Strength: Strong ๐ŸŸข
โœ… Excellent! Your password is strong and secure.

6) Extension Challenge

๐ŸŽฏ Make it more advanced

Goal: Enhance your password checker with these features:

  • Add a Tkinter GUI: Create a user-friendly interface with a password input box and color-coded strength indicator
  • Visual Strength Bar: Use ASCII or progress bar (tqdm or tkinter.ttk.Progressbar) to visualize strength
  • Password Generator Integration: Combine this with a password generator to suggest strong random passwords automatically

7) Summary

In this project, you built a real-time password strength analyzer using Python's re module.

You practiced:

  • Regex pattern matching
  • Input validation
  • Conditional logic
  • Modular function design

๐Ÿ’ก "Cybersecurity starts with strong passwords โ€” and you've just automated that with Python!"

You've now taken a real-world problem and solved it using intermediate-level programming logic that's practical, reusable, and secure.