Building a CLI Password Manager with Click and SQLite
Letโs be realโpassword management is a nightmare. You either:
- Use the same weak password for everything (bad idea).
- Store them in a Notepad file called “passwords.txt” (even worse).
- Forget them and reset them every time (annoying).
But what if you could build your own password manager in Python? One that runs from the command line and securely stores your passwords in a SQLite database?
Thatโs what weโre doing today! Weโll use Click (for a clean CLI interface) and SQLite (for safe storage) to build a simple but functional password manager.
By the end of this, youโll have:
- A CLI tool to save and retrieve passwords securely.
- A simple database that stores credentials.
- A cool hacking movie feel when you type commands.
๐ What Youโll Need
First, install Click and SQLite3 (though SQLite is built into Python):
|
|
๐ Step 1: Setting Up SQLite
We need a database to store our passwords. SQLite is perfect for this because:
- Itโs lightweight and built into Python (no setup needed).
- Itโs secure (as long as nobody gets access to the DB file).
- Itโs easy to use (because who wants complex SQL?).
Letโs create a simple database handler in a file called db.py
:
|
|
Now, we have:
โ
A database
โ
A function to add passwords
โ
A function to retrieve passwords
Letโs move to the CLI part.
๐ฎ Step 2: Building the CLI with Click
Now, letโs create password_manager.py
and hook it up with Click.
|
|
How it Works:
add <service> <username> <password>
โ Stores a password.get <service>
โ Retrieves a stored password.- Colors make it easier to read!
๐โโ๏ธ Step 3: Running Your Password Manager
1. Add a New Password
|
|
|
|
2. Retrieve a Password
|
|
|
|
โจ Boom! You now have a fully functional password manager in Python.
๐ Step 4: Improving Security (Optional)
Right now, our passwords are stored in plain textโwhich is bad.
1. Hashing Passwords
Instead of storing raw passwords, letโs hash them using bcrypt:
|
|
Modify db.py
to hash passwords before saving:
|
|
Then, change add_password()
to store the hash instead of plain text.
Now, even if someone steals your database, they wonโt be able to read the passwords!
๐ Bonus: Making It Even Cooler
- ๐ Auto-generate strong passwords using
secrets
- ๐ฆ Add categories (e.g., work, personal, banking)
- ๐ Store passwords in an encrypted file instead of SQLite
- ๐ Require a master password to access stored passwords
If youโre feeling fancy, turn this into a full GUI app later using Tkinter
or Rich
.
๐ Wrapping Up
Today, you learned how to build your own CLI password manager using:
โ
Click for an easy-to-use command-line interface
โ
SQLite for lightweight, persistent storage
โ
bcrypt for password hashing (security matters!)
Now, you never have to forget your passwords againโunless you forget the command to retrieve them. ๐