Skip to content

Commit 7c89988

Browse files
added a script that checks password strength from 1 to 5 i.e weak to strong
1 parent a5c1e10 commit 7c89988

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Password Strength Checker
2+
3+
This is a simple Python script that checks the strength of a given password based on various criteria. It evaluates the password for length, lowercase letters, uppercase letters, digits, and special characters, and provides feedback on its strength.
4+
5+
## How to Use
6+
7+
1. Clone the repository or download the script file `password_strength_checker.py`.
8+
9+
2. Run the script using Python (Python 3.x is recommended).
10+
11+
3. Enter the password you want to check when prompted.
12+
13+
4. The script will evaluate the password and display its strength along with any areas of improvement.
14+
15+
## Criteria for Password Strength
16+
17+
The password is evaluated against the following criteria:
18+
19+
- Minimum password length: The password should have at least 8 characters.
20+
21+
- At least one lowercase letter: The password should contain at least one lowercase letter (a-z).
22+
23+
- At least one uppercase letter: The password should contain at least one uppercase letter (A-Z).
24+
25+
- At least one digit: The password should contain at least one digit (0-9).
26+
27+
- At least one special character: The password should contain at least one special character (!@#$%^&*()_+=-[]{};:'",.<>?/\\|).
28+
29+
## Password Strength Scores
30+
31+
The password is given a strength score based on the number of criteria met:
32+
33+
- 1: Weak - The password does not meet the minimum length requirement.
34+
35+
- 2: Moderate - The password meets the minimum length requirement but lacks some character types.
36+
37+
- 3: Fair - The password meets the minimum length requirement and includes lowercase letters, uppercase letters, and digits.
38+
39+
- 4: Strong - The password meets the minimum length requirement and includes lowercase letters, uppercase letters, digits, and at least one special character.
40+
41+
- 5: Very Strong - The password meets all criteria and is considered very strong.
42+
43+
## Example
44+
45+
```bash
46+
$ python password_strength_checker.py
47+
Enter your password: My$3cureP@ssw0rd
48+
49+
Password Strength: 5
50+
Password is very strong!
51+
```
52+
53+
## Customization
54+
55+
You can customize the min_length variable in the script to set your desired minimum password length.
56+
57+
Feel free to modify and enhance the script according to your needs and security requirements.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import re
2+
3+
4+
def password_strength(password):
5+
"""
6+
Checks the strength of a password and returns a tuple containing the strength
7+
"""
8+
# Minimum password length
9+
min_length = 8
10+
11+
# Regular expressions to check for different character types
12+
has_lowercase = re.compile(r'[a-z]')
13+
has_uppercase = re.compile(r'[A-Z]')
14+
has_digit = re.compile(r'\d')
15+
has_special = re.compile(r'[!@#$%^&*()_+=\-[\]{};:\'",.<>?/\\|]')
16+
17+
strength = 0
18+
messages = []
19+
20+
if len(password) >= min_length:
21+
strength += 1
22+
else:
23+
messages.append("Password should have at least {} characters.".format(min_length))
24+
25+
if has_lowercase.search(password):
26+
strength += 1
27+
else:
28+
messages.append("Password should have at least one lowercase letter.")
29+
30+
if has_uppercase.search(password):
31+
strength += 1
32+
else:
33+
messages.append("Password should have at least one uppercase letter.")
34+
35+
if has_digit.search(password):
36+
strength += 1
37+
else:
38+
messages.append("Password should have at least one digit.")
39+
40+
if has_special.search(password):
41+
strength += 1
42+
else:
43+
messages.append("Password should have at least one special character.")
44+
45+
return strength, messages
46+
47+
48+
if __name__ == "__main__":
49+
password = input("Enter your password: ")
50+
strength, messages = password_strength(password)
51+
52+
print("\nPassword Strength: {}".format(strength))
53+
if strength == 5:
54+
print("Password is very strong!")
55+
else:
56+
print("Password needs improvement:")
57+
for message in messages:
58+
print("- {}".format(message))

0 commit comments

Comments
 (0)