Building a Memorable and Secure Password Generator with Python
In today's digital age, creating secure yet memorable passwords is crucial. Inspired by this need, I embarked on a project to develop a simple yet effective password generator using Python. This blog post will walk you through the journey of creating this tool, highlighting its features and the thought process behind its development.
The Idea
The concept was straightforward: generate a password that is both secure and easy to remember. The password would consist of random words and a hexadecimal number, combined into a single string. This approach leverages the human brain's ability to remember words better than random characters, while still incorporating randomness and complexity.
Specifications and Development
The project began with a clear set of specifications outlined in a markdown file (SPECS.md
). These specifications served as a blueprint for the development process:
- Read Words: The script reads words from a file named
words_alpha.txt
, filtering them to include only those with 4 to 8 characters. - Select Random Words: It selects 5 random words from the filtered list.
- Change Words to Uppercase: A random number
X
(between 1 and 4) is chosen, andX
words are converted to uppercase. - Generate Hexadecimal Number: A random hexadecimal number between 0001 and FFFF is generated.
- Generate Password: The selected words and the hexadecimal number are combined into a single string, separated by dashes.
- Multiple Passwords: The script can generate multiple passwords by specifying the number of passwords as a command-line argument.
Implementation
The script, written in Python, utilizes libraries such as random
for randomness and argparse
for handling command-line arguments. Here's a brief overview of the core functions:
read_words(file_path)
: Reads and filters words from the specified file.select_random_words(words, count=5)
: Selects a specified number of random words.change_words_to_uppercase(words, count)
: Changes a specified number of words to uppercase.generate_random_hex()
: Generates a random 4-digit hexadecimal number.generate_password(file_path)
: Combines the above functions to generate a password.
Usage
To use the password generator, ensure you have Python 3.x installed and the words_alpha.txt
file available in the same directory as the script. You can run the script using:
$ python3 pwgen.py
To generate a specific number of passwords, use:
$ python3 pwgen.py 2
Conclusion
This project was a rewarding experience, combining creativity with technical skills to solve a real-world problem. The password generator is open-source and available under the MIT License, inviting others to use, modify, and improve it. By sharing this project, I hope to contribute to the ongoing conversation about digital security and the importance of strong, memorable passwords.
Feel free to check out the GitHub repository for more details and to access the code.