Skip to content

Commit 3275d61

Browse files
authored
PR #72: Password Generator & Checker
Password Generator & Checker Merge pull request #72 from Lampard7crypt/main
2 parents 8d45c09 + 2ab490a commit 3275d61

2 files changed

Lines changed: 252 additions & 0 deletions

File tree

securepass/README.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Secure Password Manager
2+
3+
A Python utility for generating secure passwords and checking the strength of existing passwords.
4+
5+
## Features
6+
7+
- **Password Generator**: Create secure passwords with multiple options
8+
- Mix of numbers, letters, and symbols (Recommended)
9+
- Numbers only
10+
- Letters only
11+
- Symbols only
12+
- Customizable length (4-20 characters)
13+
14+
- **Password Strength Checker**: Analyze password quality and get recommendations
15+
- Check password length
16+
- Analyze character composition (uppercase, lowercase, numbers, symbols)
17+
- Receive suggestions for improvement
18+
- Detailed password report
19+
20+
## Installation
21+
22+
No external dependencies are required. This script uses only Python standard library modules.
23+
24+
```bash
25+
# Clone or download the repository
26+
# Navigate to the securepass directory
27+
cd securepass
28+
29+
# Run the script
30+
python password.py
31+
```
32+
33+
## Usage
34+
35+
Run the script and follow the interactive prompts:
36+
37+
```bash
38+
python password.py
39+
```
40+
41+
### Main Menu
42+
43+
You'll be presented with two options:
44+
1. **Generate a secure password** - Create a new password with custom specifications
45+
2. **Check strength of my password** - Analyze an existing password
46+
47+
### Generate Password Workflow
48+
49+
1. Select the password type (1-4)
50+
2. Enter desired length (4-20 characters)
51+
3. View your generated password
52+
4. Optionally get a detailed password report
53+
54+
### Check Password Strength Workflow
55+
56+
1. Enter the password you want to check
57+
2. Receive a detailed report with recommendations
58+
59+
## Example Output
60+
61+
```
62+
What would you like to do:
63+
1 Generate a secure password
64+
2 Check strength of my password
65+
> 1
66+
67+
Choose password type:
68+
1 Mix of numbers, letters and symbols (Recommended)
69+
2 Numbers only password
70+
3 Letters only password
71+
4 Symbols only password
72+
> 1
73+
74+
Enter your desired length (between 4 and 20): 12
75+
Here is your password: aB3!xK9$mQ2@
76+
77+
Would you like a report for this password? (y/n): y
78+
The password has a length of 12 characters, which meets or exceeds the recommended 8.
79+
It has 2 uppercase letter(s), 2 lowercase letter(s), 3 number(s), and 3 symbol(s).
80+
This password has a good mix of character types.
81+
```
82+
83+
## Password Strength Criteria
84+
85+
The password strength checker evaluates:
86+
87+
- **Length**: Recommends a minimum of 8 characters
88+
- **Character Diversity**: Checks for presence of:
89+
- Uppercase letters
90+
- Lowercase letters
91+
- Numbers
92+
- Symbols
93+
94+
## Functions
95+
96+
- `generate_number_only(length)` - Generates password with digits only
97+
- `generate_letters_only(length)` - Generates password with letters only
98+
- `generate_symbols_only(length)` - Generates password with symbols only
99+
- `mix_of_all(length)` - Generates password with mix of all character types
100+
- `password_report(password)` - Analyzes password strength and returns report
101+
102+
## Requirements
103+
104+
- Python 3.x
105+
- No external packages required
106+
107+
## Best Practices
108+
109+
- Use "Mix of numbers, letters and symbols" for the strongest passwords
110+
- Maintain a minimum length of 12 characters for sensitive accounts
111+
- Store generated passwords securely (consider using a password manager)
112+
- Regularly update passwords for important accounts
113+
- Never share passwords or store them in plain text
114+
115+
## License
116+
117+
This project is part of the Python-Projects repository by Grow-with-Open-Source.

securepass/password.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import random
2+
import string
3+
4+
5+
def main():
6+
option = ""
7+
while option not in ("1", "2"):
8+
option = input(
9+
"What would you like to do:\n"
10+
"1 Generate a secure password\n"
11+
"2 Check the strength of my password\n> "
12+
)
13+
if option not in ("1", "2"):
14+
print("Please choose 1 or 2.")
15+
16+
if option == "1":
17+
choice = None
18+
length = None
19+
while choice not in (1, 2, 3, 4):
20+
try:
21+
choice = int(
22+
input(
23+
"Choose password type:\n"
24+
"1 Mix of numbers, letters and symbols (Recommended)\n"
25+
"2 Numbers only password\n"
26+
"3 Letters only password\n"
27+
"4 Symbols only password\n> "
28+
)
29+
)
30+
if choice not in (1, 2, 3, 4):
31+
print("Invalid choice, try again.")
32+
except ValueError:
33+
print("Invalid input, enter numbers only.")
34+
while length not in range(4, 21):
35+
try:
36+
length = int(input("Enter your desired length (between 4 and 20): "))
37+
if length not in range(4, 21):
38+
print("Invalid length, try again.")
39+
except ValueError:
40+
print("Invalid input, enter numbers only.")
41+
42+
if choice == 1:
43+
passwd = mix_of_all(length)
44+
elif choice == 2:
45+
passwd = generate_number_only(length)
46+
elif choice == 3:
47+
passwd = generate_letters_only(length)
48+
else:
49+
passwd = generate_symbols_only(length)
50+
51+
print("Here is your password:", passwd)
52+
53+
if input("Would you like a report for this password? (y/n): ").lower() == "y":
54+
print(password_report(passwd))
55+
56+
else: # option == "2"
57+
existing = input("Enter the password you want to check: ")
58+
print(password_report(existing))
59+
60+
61+
def generate_number_only(length):
62+
digits = string.digits
63+
return "".join(random.choice(digits) for _ in range(length))
64+
65+
66+
def generate_letters_only(length):
67+
letters = string.ascii_letters
68+
return "".join(random.choice(letters) for _ in range(length))
69+
70+
71+
def generate_symbols_only(length):
72+
symbols = "!@#$%^&*()-_=+[]{};:,.<>?/\\|"
73+
return "".join(random.choice(symbols) for _ in range(length))
74+
75+
76+
def mix_of_all(length):
77+
pool = string.ascii_letters + string.digits + "!@#$%^&*()-_=+[]{};:,.<>?/\\|"
78+
return "".join(random.choice(pool) for _ in range(length))
79+
80+
81+
def password_report(password: str) -> str:
82+
recommended_length = 8
83+
84+
length = len(password)
85+
upper = lower = digits = symbols = 0
86+
for letter in password:
87+
if letter.isupper():
88+
upper += 1
89+
elif letter.islower():
90+
lower += 1
91+
elif letter.isdigit():
92+
digits += 1
93+
else:
94+
symbols += 1
95+
96+
parts = []
97+
98+
# Length report
99+
diff = recommended_length - length
100+
if diff > 0:
101+
parts.append(
102+
f"The password has a length of {length} characters, {diff} less than the recommended {recommended_length}."
103+
)
104+
else:
105+
parts.append(
106+
f"The password has a length of {length} characters, which meets or exceeds the recommended {recommended_length}."
107+
)
108+
109+
# Composition report
110+
parts.append(
111+
f"It has {upper} uppercase letter(s), {lower} lowercase letter(s), {digits} number(s), and {symbols} symbol(s)."
112+
)
113+
114+
suggestions = []
115+
if upper == 0:
116+
suggestions.append("add at least one uppercase letter")
117+
if lower == 0:
118+
suggestions.append("add at least one lowercase letter")
119+
if digits == 0:
120+
suggestions.append("add at least one number")
121+
if symbols == 0:
122+
suggestions.append("add a symbol for extra strength")
123+
124+
if suggestions:
125+
parts.append(
126+
"To improve this password, you could " + ", ".join(suggestions) + "."
127+
)
128+
else:
129+
parts.append("This password has a good mix of character types.")
130+
131+
return " ".join(parts)
132+
133+
134+
if __name__ == '__main__':
135+
main()

0 commit comments

Comments
 (0)