GUI to generate and store passwords in SQLite using Python
In this century there are many social media accounts, websites, or any online account that needs a secure password. Often we use the same password for multiple accounts and the basic drawback to that is if somebody gets to know about your password then he/she has the access to all your accounts. It is hard to remember all the distinct passwords. We can achieve that by creating a simple GUI program using python, Tkinter, and SQLite.
This application will generate a password based on the desired length given as input by the user. It will also save the password along with account user_id and the name of the site to a database. You can even update your old password or username.
The user will specify the length of the password they want to generate. The program will generate a random string of the specified length using the random function. The user will provide the details of the user ID and the site name associated with the account, and hit the save to database button, which will trigger the insert() function of the backend.py file given in the latter part of this article. Hence, saving the data into the database without writing any SQL command.
- webbrowser: This module is used to display the help.txt file in notepad.
- Tkinter: Tkinter is GUI or graphical user interface package in python. It is used for creating GUI applications in python.
- SQLite3: Sqlite is a lightweight and easy-to-use database engine, which follows similar syntax to that of Postgres SQL. SQLite3 module in python helps us to execute SQL commands using python codes.
- ttkbootsrtap: This module changes the appearance of the GUI application. It’s similar to bootstrap in web development, which is used to give a promising look to web pages. This module can be installed in the following ways:
pip install ttkbootstrap
- csv: This module will help to save the data of the database in a .csv format, which later on be viewed in excel.
pip install python-csv
First, all the required modules are imported. Then 4 lists to represent lowercase, uppercase alphabets, and symbols is initialized, inside the class window as class variables. Then, the whole layout of the application is created under the __init__ function so that all these Tkinter objects are created at the time of declaring an object of the class window.
Ttkbootstrap package allows you to change the style of the Tkinter objects this includes everything Tkinter has to offer. This will basically change the theme of the application. It comes with many inbuilt themes ex. cyborg, darkly etc.
Syntax with ttkbootstrap:
Earlier syntax without ttkbootstrap:
Password generator Function- generator() runs a loop for chosen password length /4. The length given by the user will always be multiple of 4 since those are the only options given in the dropdown menu. With each iteration choose a random character from the class variable created, using a random function. ex. a0=random.choice(list_name). After choosing and storing the characters from 4 different lists(class variables) into 4 variables of suitable data type, concatenate the 4 variables and store the sum in another variable.
Below is the implementation:
Program: Window to generate passwords
Backend program using SQLite: Sqlite3 module of python allows us to execute sol commands using Python. Following is the syntax
- It will make a connection to the SQLite database file
- Cursor for dataset traversal
- To execute the SQL commands
- Commit or save the changes made
- This for closing the connection created with SQLite database file
Note: Here the password is been taken as a primary key. So to change the password you need to insert the new one and delete the old one from the database.
Program: Backend program using SQLite: