A secure and customizable password generator built with Python that creates cryptographically strong passwords using the secrets module.
- Generates cryptographically secure passwords
- Customizable password length (6-128 characters)
- Option to include/exclude digits and symbols
- Generates multiple passwords at once
- Save passwords to a text file
- Input validation and error handling
- Python 3.6 or higher
- Clone or download the
password.pyfile to your local machine - No additional dependencies required - uses only Python's standard library
git clone https://github.com/Grow-with-Open-Source/Python-Projects.git
cd Python-Projects
cd Password-Generator
python password.pyRun the script from your terminal or command prompt:
python password.pyfrom password import generate_password
# Generate a single password
password = generate_password(length=12, digits=True, symbols=True)
print(password)
# Generate without symbols
simple_password = generate_password(length=10, digits=True, symbols=False)
print(simple_password)> python password.py
Enter the length of the password: 12
Enter the number of passwords to generate: 3
Include digits? (y/n): y
Include symbols? (y/n): y
Generating Secure Passwords...
Password #1: aB3@kL9#mN2!
Password #2: pQ8$rS1^tU4*
Password #3: xY7&zW5!vZ9@
Do you want to save the passwords to a file? (y/n): y
Enter the name of the file (without .txt): my_passwords
Saving passwords to file...
Passwords saved successfully!> python password.py
Enter the length of the password: 8
Enter the number of passwords to generate: 2
Include digits? (y/n): y
Include symbols? (y/n): n
Generating Secure Passwords...
Password #1: aB3cD9eF
Password #2: gH4iJ7kL> python password.py
Enter the length of the password: 4
Enter the number of passwords to generate: 1
Include digits? (y/n): y
Include symbols? (y/n): y
Password is too short - Generating Passwords of length 6
Generating Secure Passwords...
Password #1: a@3b#9When you run the script, you'll be prompted for the following:
- Password Length: Enter an integer between 6 and 128
- If you enter less than 6, it will automatically set to 6
- Maximum length is 128 characters
-
Number of Passwords: How many passwords to generate (positive integer)
-
Include Digits?: (y/n) - Whether to include numbers (0-9)
-
Include Symbols?: (y/n) - Whether to include special characters (!@#$%^&*(), etc.)
-
Save to File?: (y/n) - Option to save generated passwords to a text file
- If yes, you can specify a filename (default: "passwords.txt")
-
Cryptographically Secure: Uses
secretsmodule (notrandom) for true randomness -
Character Variety: Ensures at least one character from each selected character set
-
Shuffling: Passwords are shuffled after generation to avoid predictable patterns
-
Length Enforcement: Minimum 6 characters for basic security
-
Input Validation: Validates all user inputs to prevent errors
password.py
├── generate_password(length, digits, symbols) # Core generator function
├── save(passwords) # File saving function
└── main() # Interactive CLI interface
The script includes comprehensive error handling for:
- Invalid integer inputs
- File system errors when saving
- Unexpected exceptions
- Length constraints and requirements
- Maximum password length is 128 characters
- Minimum password length is 6 characters (enforced)
- Uses standard Python string punctuation for symbols
- Text file saving is optional and basic
- ✅ Uses secrets module for cryptographically secure random generation
- ✅ No external dependencies or network calls
- ✅ Passwords are generated locally on your machine
- ❗ Saved passwords are stored in plain text - handle with care!
- ❗ Always use strong, unique passwords for different services
This project is open-source and intended for educational and practical use. Refer to the repository license for usage terms.