Skip to content

Commit d9d1873

Browse files
authored
Merge pull request animator#402 from Anshika14528/passwordChecker1
Closes animator#294 - Mini Project : Password Strength Checker
2 parents a83914c + b8926c4 commit d9d1873

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

contrib/mini-projects/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
- [Dice Roller](dice_roller.md)
44
- [Rock Paper Scissors Game](Rock_Paper_Scissors_Game.md)
5+
- [Password strength checker](password_strength_checker.md)
56
- [Path Finder](path-finder.md)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# about password strength
2+
3+
> This code is a simple password strength checker.
4+
It evaluates the strength of a user's password based on the presence of
5+
uppercase letters, lowercase letters, digits, spaces, and special characters.
6+
7+
### About the code:
8+
9+
- The codebase is break down in two file `password_strength_checker.py` and `main.py`.
10+
11+
`password_strength_checker.py` The function evaluates password strength based on character types (uppercase, lowercase, digits, spaces, special characters) and provides feedback on its security.
12+
and `main.py` contains basic code.
13+
14+
```
15+
import string
16+
17+
18+
class password_checker:
19+
def __init__(self, password):
20+
self.password = password
21+
22+
def check_password_strength(self):
23+
"""This function prompts the user to enter a password and then evaluates its strength."""
24+
25+
password_strength = 0
26+
upper_count = 0
27+
lower_count = 0
28+
num_count = 0
29+
space_count = 0
30+
specialcharacter_count = 0
31+
review = ""
32+
33+
for char in list(password):
34+
if char in string.ascii_uppercase:
35+
upper_count += 1
36+
elif char in string.ascii_lowercase:
37+
lower_count += 1
38+
elif char in string.digits:
39+
num_count += 1
40+
elif char == " ":
41+
space_count += 1
42+
else:
43+
specialcharacter_count += 1
44+
45+
if upper_count >= 1:
46+
password_strength += 1
47+
if lower_count >= 1:
48+
password_strength += 1
49+
if num_count >= 1:
50+
password_strength += 1
51+
if space_count >= 1:
52+
password_strength += 1
53+
if specialcharacter_count >= 1:
54+
password_strength += 1
55+
56+
if password_strength == 1:
57+
review = "That's a very easy password, Not good for use"
58+
elif password_strength == 2:
59+
review = (
60+
"That's a weak password, You should change it to some strong password."
61+
)
62+
elif password_strength == 3:
63+
review = "Your password is just okay, you may change it."
64+
elif password_strength == 4:
65+
review = "Your password is hard to guess."
66+
elif password_strength == 5:
67+
review = "Its the strong password, No one can guess this password "
68+
69+
about_password = {
70+
"uppercase_letters ": upper_count,
71+
"lowercase_letters": lower_count,
72+
"space_count": space_count,
73+
"specialcharacter_count": specialcharacter_count,
74+
"password_strength": password_strength,
75+
"about_password_strength": review,
76+
}
77+
print(about_password)
78+
79+
def check_password():
80+
"""This function prompts the user to decide if they want to check their password strength."""
81+
82+
choice = input("Do you want to check your password's strength? (Y/N): ")
83+
if choice.upper() == "Y":
84+
return True
85+
elif choice.upper() == "N":
86+
return False
87+
else:
88+
print("Invalid input. Please enter 'Y' for Yes or 'N' for No.")
89+
return password_checker.check_password()
90+
91+
```
92+
### Here's the implementation of 'main.py'
93+
```
94+
import password_checker from password_strength_checker
95+
96+
while password_checker.check_password():
97+
password = input("Enter your password: ")
98+
p = password_checker(password)
99+
p.check_password_strength()
100+
```

0 commit comments

Comments
 (0)