How I built a Secure Password Generator in Python - And What I learned
June 17, 2025
So I had this idea to build a command-line password generator today, and I thought it would be a cool Python project to test my skills. I only had a few hours and not much experience writing Python, so this pushed me outside my comfort zone.
But I learned a lot. One hour turned into two pretty quickly as I got everything working. Here’s what I built and what I ran into along the way.
What I Built (and What I Learned)
It’s a simple python script that you can run in the terminal that generates a random password using the secrets
module instead of the random
module.
The difference is that secrets
is used to generate cryptographically strong random numbers and is good for things like passwords, tokens and account authentication. If you have never used it before, it is a cool module that you should try.
I could have just used random
, but that is for generating random general purpose numbers for things like games, data analysis and other projects where you just need some random numbers generated.
I chose to use secrets
because I was building a password generator, so it made sense.
After that I decided to add a feature to copy it to the system clipboard for 10 seconds and then auto-clear. This was for privacy and you never want to leave sensitive data on the clipboard like that… I mean its not good practice so we try to avoid that.
To get this working, I needed pyperclip
, which turned out to be a bit of a headache on Ubuntu/Debian. You can’t install it globally with pip
because it might break system Python. So I had to set up a virtual environment with python3.12-venv
, activate it, and install the package there.
Debian based distros don’t let you do that from the command line because it could break something in the package manager, so I had to set up a virtual environment using python3.12-venv
and then run the damn thing so I could run my program.
It took a little bit of research, but I got it figured out.
I also had to install a program to be able to access the system clipboard which was pretty straightforward. Just:
sudo apt install xclip
and I solved that problem.
Then I was able to run the program and verify everything worked as it should. I had to fix a few small typos, but other than that, everything ran as it should so I pushed it to github.
Takeaways
It’s OK to start small. Simple tools like a random password generator teach you a lot when you build them yourself.
And even if you don’t have a ton of time, you can do something small everyday to level up your skills. That’s where the real magic happens.
Grinding it out for an hour or 2 and then taking a break is a great way to solidify what you are learning and give your brain a chance to make sense of everything.
Outro
So a small project like this took me one step closer to being a better developer.
The kind that I want to become, and you can only get there through hard work, even if it is only for an hour or two a night.
Just be consistent and show up everyday. Thanks for reading.