Categories We Write About

Create a password strength checker

Here’s a simple yet effective password strength checker implemented in Python. It evaluates passwords based on common criteria like length, use of uppercase/lowercase letters, digits, special characters, and gives a strength rating.

python
import re def password_strength(password): length_criteria = len(password) >= 8 upper_criteria = re.search(r'[A-Z]', password) is not None lower_criteria = re.search(r'[a-z]', password) is not None digit_criteria = re.search(r'd', password) is not None special_criteria = re.search(r'[W_]', password) is not None # Non-alphanumeric characters score = sum([length_criteria, upper_criteria, lower_criteria, digit_criteria, special_criteria]) if score == 5: return "Very Strong" elif score == 4: return "Strong" elif score == 3: return "Medium" elif score == 2: return "Weak" else: return "Very Weak" # Example usage: password = input("Enter your password to check strength: ") print("Password strength:", password_strength(password))

How it works:

  • Checks if the password has at least 8 characters.

  • Checks for uppercase letters.

  • Checks for lowercase letters.

  • Checks for digits.

  • Checks for special characters (anything that is not a letter or number).

  • Scores 0–5 based on criteria met and returns a descriptive strength.

If you want it for a different programming language or with additional features, just let me know!

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About