Skip to content

Commit 5c12671

Browse files
committed
Initil commit. This is a script used to either generate a password or check strength of your password.
1 parent 7841987 commit 5c12671

2 files changed

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

0 commit comments

Comments
 (0)