diff --git a/securepass/README.md b/securepass/README.md new file mode 100644 index 0000000..e79364b --- /dev/null +++ b/securepass/README.md @@ -0,0 +1,117 @@ +# Secure Password Manager + +A Python utility for generating secure passwords and checking the strength of existing passwords. + +## Features + +- **Password Generator**: Create secure passwords with multiple options + - Mix of numbers, letters, and symbols (Recommended) + - Numbers only + - Letters only + - Symbols only + - Customizable length (4-20 characters) + +- **Password Strength Checker**: Analyze password quality and get recommendations + - Check password length + - Analyze character composition (uppercase, lowercase, numbers, symbols) + - Receive suggestions for improvement + - Detailed password report + +## Installation + +No external dependencies are required. This script uses only Python standard library modules. + +```bash +# Clone or download the repository +# Navigate to the securepass directory +cd securepass + +# Run the script +python password.py +``` + +## Usage + +Run the script and follow the interactive prompts: + +```bash +python password.py +``` + +### Main Menu + +You'll be presented with two options: +1. **Generate a secure password** - Create a new password with custom specifications +2. **Check strength of my password** - Analyze an existing password + +### Generate Password Workflow + +1. Select the password type (1-4) +2. Enter desired length (4-20 characters) +3. View your generated password +4. Optionally get a detailed password report + +### Check Password Strength Workflow + +1. Enter the password you want to check +2. Receive a detailed report with recommendations + +## Example Output + +``` +What would you like to do: +1 Generate a secure password +2 Check strength of my password +> 1 + +Choose password type: +1 Mix of numbers, letters and symbols (Recommended) +2 Numbers only password +3 Letters only password +4 Symbols only password +> 1 + +Enter your desired length (between 4 and 20): 12 +Here is your password: aB3!xK9$mQ2@ + +Would you like a report for this password? (y/n): y +The password has a length of 12 characters, which meets or exceeds the recommended 8. +It has 2 uppercase letter(s), 2 lowercase letter(s), 3 number(s), and 3 symbol(s). +This password has a good mix of character types. +``` + +## Password Strength Criteria + +The password strength checker evaluates: + +- **Length**: Recommends a minimum of 8 characters +- **Character Diversity**: Checks for presence of: + - Uppercase letters + - Lowercase letters + - Numbers + - Symbols + +## Functions + +- `generate_number_only(length)` - Generates password with digits only +- `generate_letters_only(length)` - Generates password with letters only +- `generate_symbols_only(length)` - Generates password with symbols only +- `mix_of_all(length)` - Generates password with mix of all character types +- `password_report(password)` - Analyzes password strength and returns report + +## Requirements + +- Python 3.x +- No external packages required + +## Best Practices + +- Use "Mix of numbers, letters and symbols" for the strongest passwords +- Maintain a minimum length of 12 characters for sensitive accounts +- Store generated passwords securely (consider using a password manager) +- Regularly update passwords for important accounts +- Never share passwords or store them in plain text + +## License + +This project is part of the Python-Projects repository by Grow-with-Open-Source. diff --git a/securepass/password.py b/securepass/password.py new file mode 100644 index 0000000..e617355 --- /dev/null +++ b/securepass/password.py @@ -0,0 +1,126 @@ +import random +import string + + +def main(): + while True: + option = input( + "What would you like to do:\n" + "1 Generate a secure password\n" + "2 Check strength of my password\n> " + ) + if option not in ("1", "2"): + print("Please choose 1 or 2.") + continue + break + + if option == "1": + while True: + try: + choice = int( + input( + "Choose password type:\n" + "1 Mix of numbers, letters and symbols (Recommended)\n" + "2 Numbers only password\n" + "3 Letters only password\n" + "4 Symbols only password\n> " + ) + ) + length = int(input("Enter your desired length (between 4 and 20): ")) + except ValueError: + print("Invalid input, enter numbers only.") + continue + + if choice not in (1, 2, 3, 4) or length not in range(4, 21): + print("Invalid input, try again.") + continue + break + + if choice == 1: + passwd = mix_of_all(length) + elif choice == 2: + passwd = generate_number_only(length) + elif choice == 3: + passwd = generate_letters_only(length) + else: + passwd = generate_symbols_only(length) + + print("Here is your password:", passwd) + + if input("Would you like a report for this password? (y/n): ").lower() == "y": + print(password_report(passwd)) + + else: # option == "2" + existing = input("Enter the password you want to check: ") + print(password_report(existing)) + + +def generate_number_only(length): + digits = string.digits + return "".join(random.choice(digits) for _ in range(length)) + + +def generate_letters_only(length): + letters = string.ascii_letters + return "".join(random.choice(letters) for _ in range(length)) + + +def generate_symbols_only(length): + symbols = "!@#$%^&*()-_=+[]{};:,.<>?/\\|" + return "".join(random.choice(symbols) for _ in range(length)) + + +def mix_of_all(length): + pool = string.ascii_letters + string.digits + "!@#$%^&*()-_=+[]{};:,.<>?/\\|" + return "".join(random.choice(pool) for _ in range(length)) + + +def password_report(password: str) -> str: + recommended_length = 8 + + length = len(password) + upper = sum(1 for ch in password if ch.isupper()) + lower = sum(1 for ch in password if ch.islower()) + digits = sum(1 for ch in password if ch.isdigit()) + symbols = sum(1 for ch in password if not ch.isalnum()) + + parts = [] + + # Length report + diff = recommended_length - length + if diff > 0: + parts.append( + f"The password has a length of {length} characters, {diff} less than the recommended {recommended_length}." + ) + else: + parts.append( + f"The password has a length of {length} characters, which meets or exceeds the recommended {recommended_length}." + ) + + # Composition report + parts.append( + f"It has {upper} uppercase letter(s), {lower} lowercase letter(s), {digits} number(s), and {symbols} symbol(s)." + ) + + suggestions = [] + if upper == 0: + suggestions.append("add at least one uppercase letter") + if lower == 0: + suggestions.append("add at least one lowercase letter") + if digits == 0: + suggestions.append("add at least one number") + if symbols == 0: + suggestions.append("add a symbol for extra strength") + + if suggestions: + parts.append( + "To improve this password, you could " + ", ".join(suggestions) + "." + ) + else: + parts.append("This password has a good mix of character types.") + + return " ".join(parts) + + +if __name__ == '__main__': + main()