๐ Day 101/150 – Password Strength Checker in Python
A strong password helps protect your accounts from unauthorized access. A good password should contain a mix of uppercase letters, lowercase letters, numbers, and special characters, and it should be at least 8 characters long.
In this post, we'll explore four different ways to check password strength in Python.
Method 1 – Check Password Length
The simplest way to check whether a password is strong is by verifying its length.
password = input("Enter your password: ")
if len(password) >= 8:
print("Strong Password")
else:
print("Weak Password")
Sample Input
python123Output
Strong PasswordExplanation
input() reads the password entered by the user.
len() calculates the password length.
If the length is 8 or more, the password is considered strong.
Otherwise, it is considered weak.
Method 2 – Check for Uppercase, Lowercase, and Digits
Verify that the password contains different types of characters.
Python123password = input("Enter your password: ") has_upper = any(char.isupper() for char in password) has_lower = any(char.islower() for char in password) has_digit = any(char.isdigit() for char in password) if has_upper and has_lower and has_digit: print("Strong Password") else: print("Weak Password")
Sample Input
Output
Strong PasswordExplanation
isupper() checks for uppercase letters.
islower() checks for lowercase letters.
isdigit() checks for numeric digits.
any() returns True if at least one matching character is found.
The password is strong only if all three conditions are satisfied.
Method 3 – Check for Special Characters
Require the password to include at least one special character.
Python@123password = input("Enter your password: ") special = "!@#$%^&*()_+-=[]{}|;:',.<>?/" has_special = any(char in special for char in password) if has_special: print("Password contains a special character.") else: print("Password needs a special character.")
Sample Input
Output
Password contains a special character.Explanation
A string of allowed special characters is created.
The program checks whether any character in the password belongs to that string.
A password with at least one special character is generally more secure.
Method 4 – Complete Password Strength Checker
Combine all the checks into a single program.
password = input("Enter your password: ")
special = "!@#$%^&*()_+-=[]{}|;:',.<>?/"
if (len(password) >= 8 and
any(char.isupper() for char in password) and
any(char.islower() for char in password) and
any(char.isdigit() for char in password) and
any(char in special for char in password)):
print("Strong Password")
else:
print("Weak Password")
Sample Input
Python@123Output
Strong PasswordExplanation
The password must be at least 8 characters long.
It must contain:
At least one uppercase letter.
At least one lowercase letter.
At least one digit.
At least one special character.
If all conditions are met, the password is considered strong.
Comparison of Methods
| Method | Best For |
|---|---|
| Check Length | Basic password validation |
| Character Type Check | Checking letters and numbers |
| Special Character Check | Improving password security |
| Complete Password Checker | Real-world password validation |
๐ฅ Key Takeaways
A strong password should be at least 8 characters long.
Include uppercase letters, lowercase letters, digits, and special characters.
Functions like isupper(), islower(), isdigit(), and any() make password validation simple.
Combining multiple checks provides better password security.
Password strength checkers are commonly used in login and registration systems.
Stay tuned for Day 102 of the #150DaysOfPython series! ๐


.png)
