Skip to content

Password Strength Checker

Abstract

Password Strength Checker is a Python application that evaluates the strength of passwords based on various security criteria. The application checks for minimum length requirements, presence of uppercase and lowercase letters, numbers, and special characters. It provides immediate feedback to users about password weaknesses and suggestions for improvement. This project demonstrates the use of regular expressions, string analysis, and security best practices in Python programming.

Prerequisites

  • Python 3.6 or above
  • A code editor or IDE

Before you Start

Before starting this project, you must have Python installed on your computer. If you don’t have Python installed, you can download it from here. You must have a code editor or IDE installed on your computer. If you don’t have any code editor or IDE installed, you can download Visual Studio Code from here.

Note: This project uses only built-in Python modules (rere for regular expressions), so no additional installations are required.

Getting Started

Create a Project

  1. Create a folder named password-strength-checkerpassword-strength-checker.
  2. Open the folder in your favorite code editor or IDE.
  3. Create a file named passwordstrengthchecker.pypasswordstrengthchecker.py.
  4. Copy the given code and paste it in your passwordstrengthchecker.pypasswordstrengthchecker.py file.

Write the Code

  1. Copy and paste the following code in your passwordstrengthchecker.pypasswordstrengthchecker.py file.
⚙️ Password Strength Checker
Password Strength Checker
# Password Strength Checker
 
import re
 
def password_strength_checker(password):
    if len(password) < 8:
        print("Password must be at least 8 characters long.")
    elif not re.search("[a-z]", password):
        print("Password must contain at least one lowercase letter.")
    elif not re.search("[A-Z]", password):
        print("Password must contain at least one uppercase letter.")
    elif not re.search("[0-9]", password):
        print("Password must contain at least one number.")
    elif not re.search("[_@$]", password):
        print("Password must contain at least one special character.")
    else:
        print("Password is strong.")
        
password_strength_checker("Password123")
password_strength_checker("Password")
password_strength_checker("password123")
password_strength_checker("PASSWORD123")
password_strength_checker("Password@")
password_strength_checker("Password123@")
password_strength_checker("Password123@!")
 
Password Strength Checker
# Password Strength Checker
 
import re
 
def password_strength_checker(password):
    if len(password) < 8:
        print("Password must be at least 8 characters long.")
    elif not re.search("[a-z]", password):
        print("Password must contain at least one lowercase letter.")
    elif not re.search("[A-Z]", password):
        print("Password must contain at least one uppercase letter.")
    elif not re.search("[0-9]", password):
        print("Password must contain at least one number.")
    elif not re.search("[_@$]", password):
        print("Password must contain at least one special character.")
    else:
        print("Password is strong.")
        
password_strength_checker("Password123")
password_strength_checker("Password")
password_strength_checker("password123")
password_strength_checker("PASSWORD123")
password_strength_checker("Password@")
password_strength_checker("Password123@")
password_strength_checker("Password123@!")
 
  1. Save the file.
  2. Open the terminal in your code editor or IDE and navigate to the folder password-strength-checkerpassword-strength-checker.
command
C:\Users\Your Name\password-strength-checker> python passwordstrengthchecker.py
Password must contain at least one special character.
Password must be at least 8 characters long.
Password must contain at least one uppercase letter.
Password must contain at least one lowercase letter.
Password must contain at least one number.
Password must contain at least one special character.
Password is strong.
Password is strong.
command
C:\Users\Your Name\password-strength-checker> python passwordstrengthchecker.py
Password must contain at least one special character.
Password must be at least 8 characters long.
Password must contain at least one uppercase letter.
Password must contain at least one lowercase letter.
Password must contain at least one number.
Password must contain at least one special character.
Password is strong.
Password is strong.

Explanation

  1. Import the required module.
passwordstrengthchecker.py
import re
passwordstrengthchecker.py
import re
  1. Define the password strength checking function.
passwordstrengthchecker.py
def password_strength_checker(password):
passwordstrengthchecker.py
def password_strength_checker(password):
  1. Check minimum length requirement.
passwordstrengthchecker.py
if len(password) < 8:
    print("Password must be at least 8 characters long.")
passwordstrengthchecker.py
if len(password) < 8:
    print("Password must be at least 8 characters long.")
  1. Check for lowercase letters using regular expressions.
passwordstrengthchecker.py
elif not re.search("[a-z]", password):
    print("Password must contain at least one lowercase letter.")
passwordstrengthchecker.py
elif not re.search("[a-z]", password):
    print("Password must contain at least one lowercase letter.")
  1. Check for uppercase letters.
passwordstrengthchecker.py
elif not re.search("[A-Z]", password):
    print("Password must contain at least one uppercase letter.")
passwordstrengthchecker.py
elif not re.search("[A-Z]", password):
    print("Password must contain at least one uppercase letter.")
  1. Check for numbers.
passwordstrengthchecker.py
elif not re.search("[0-9]", password):
    print("Password must contain at least one number.")
passwordstrengthchecker.py
elif not re.search("[0-9]", password):
    print("Password must contain at least one number.")
  1. Check for special characters.
passwordstrengthchecker.py
elif not re.search("[_@$]", password):
    print("Password must contain at least one special character.")
passwordstrengthchecker.py
elif not re.search("[_@$]", password):
    print("Password must contain at least one special character.")
  1. Confirm strong password.
passwordstrengthchecker.py
else:
    print("Password is strong.")
passwordstrengthchecker.py
else:
    print("Password is strong.")
  1. Test the function with various passwords.
passwordstrengthchecker.py
password_strength_checker("Password123")
password_strength_checker("Password")
password_strength_checker("password123")
password_strength_checker("PASSWORD123")
password_strength_checker("Password@")
password_strength_checker("Password123@")
password_strength_checker("Password123@!")
passwordstrengthchecker.py
password_strength_checker("Password123")
password_strength_checker("Password")
password_strength_checker("password123")
password_strength_checker("PASSWORD123")
password_strength_checker("Password@")
password_strength_checker("Password123@")
password_strength_checker("Password123@!")

Security Criteria Checked

The application evaluates passwords based on these criteria:

1. Length Requirement

  • Minimum 8 characters
  • Longer passwords provide better security

2. Lowercase Letters

  • Must contain at least one lowercase letter (a-z)
  • Increases character set complexity

3. Uppercase Letters

  • Must contain at least one uppercase letter (A-Z)
  • Adds to password entropy

4. Numbers

  • Must contain at least one digit (0-9)
  • Numerical characters increase complexity

5. Special Characters

  • Must contain at least one special character (_, @, $)
  • Note: Current implementation checks for limited special characters

Features

  • Comprehensive Checking: Evaluates multiple security criteria
  • Immediate Feedback: Provides specific weakness identification
  • Regular Expression Power: Uses regex for pattern matching
  • Simple Interface: Easy-to-use function-based approach
  • Batch Testing: Can test multiple passwords at once
  • Clear Messages: Specific feedback for each security requirement

Regular Expression Patterns

The application uses these regex patterns:

  • [a-z][a-z]: Matches any lowercase letter
  • [A-Z][A-Z]: Matches any uppercase letter
  • [0-9][0-9]: Matches any digit
  • [_@$][_@$]: Matches specific special characters

Sample Test Results

Password123     → Missing special character
Password        → Too short, missing numbers and special characters
password123     → Missing uppercase and special characters
PASSWORD123     → Missing lowercase and special characters
Password@       → Missing numbers
Password123@    → Strong password ✓
Password123@!   → Strong password ✓
Password123     → Missing special character
Password        → Too short, missing numbers and special characters
password123     → Missing uppercase and special characters
PASSWORD123     → Missing lowercase and special characters
Password@       → Missing numbers
Password123@    → Strong password ✓
Password123@!   → Strong password ✓

Next Steps

You can enhance this project by:

  • Adding a GUI interface using Tkinter
  • Implementing a scoring system (weak, medium, strong)
  • Expanding special character requirements
  • Adding checks for common passwords
  • Implementing password generation suggestions
  • Adding dictionary word detection
  • Creating visual strength indicators
  • Adding entropy calculation
  • Implementing sequential character detection
  • Adding customizable security requirements

Enhanced Version Ideas

passwordstrengthchecker.py
def enhanced_password_checker(password):
    score = 0
    feedback = []
    
    # Length scoring
    if len(password) >= 12:
        score += 2
    elif len(password) >= 8:
        score += 1
    else:
        feedback.append("Password too short")
    
    # Character type scoring
    if re.search("[a-z]", password):
        score += 1
    if re.search("[A-Z]", password):
        score += 1
    if re.search("[0-9]", password):
        score += 1
    if re.search("[!@#$%^&*()_+\-=\[\]{};':\"\\|,.<>\/?]", password):
        score += 2
    
    # Return strength level
    if score >= 7:
        return "Very Strong"
    elif score >= 5:
        return "Strong"
    elif score >= 3:
        return "Medium"
    else:
        return "Weak"
passwordstrengthchecker.py
def enhanced_password_checker(password):
    score = 0
    feedback = []
    
    # Length scoring
    if len(password) >= 12:
        score += 2
    elif len(password) >= 8:
        score += 1
    else:
        feedback.append("Password too short")
    
    # Character type scoring
    if re.search("[a-z]", password):
        score += 1
    if re.search("[A-Z]", password):
        score += 1
    if re.search("[0-9]", password):
        score += 1
    if re.search("[!@#$%^&*()_+\-=\[\]{};':\"\\|,.<>\/?]", password):
        score += 2
    
    # Return strength level
    if score >= 7:
        return "Very Strong"
    elif score >= 5:
        return "Strong"
    elif score >= 3:
        return "Medium"
    else:
        return "Weak"

Common Password Weaknesses

  • Too short: Less than 8 characters
  • Single case: Only uppercase or lowercase
  • No numbers: Missing numerical characters
  • No symbols: Missing special characters
  • Dictionary words: Common words that can be found in dictionaries
  • Personal info: Names, birthdays, addresses
  • Sequential patterns: 123456, abcdef, qwerty

Security Best Practices

  • Use unique passwords: Different password for each account
  • Enable 2FA: Two-factor authentication when available
  • Regular updates: Change passwords periodically
  • Use password managers: Store complex passwords securely
  • Avoid personal info: Don’t use easily guessable information

Educational Value

This project teaches:

  • Regular expressions: Pattern matching in strings
  • Conditional logic: Multiple if-elif-else statements
  • String analysis: Character type identification
  • Security concepts: Password strength principles
  • Function design: Modular code organization

Conclusion

In this project, we learned how to create a Password Strength Checker using Python’s regular expression module. We explored pattern matching techniques, security criteria evaluation, and user feedback systems. This project provides valuable insights into cybersecurity practices and demonstrates practical applications of string analysis in Python. The concepts learned here can be extended to more advanced security applications and validation systems. To find more projects like this, you can visit Python Central Hub.

Was this page helpful?

Let us know how we did