Python Project — The Account information saver 5000!

Kristian Roopnarine
6 min readSep 30, 2019

Do you use Google passwords to save all your passwords? Do you struggle to remember account information for all the websites you’re registered to? Look no further as I made an app that can save you the hustle of password resetting!

Picture from https://www.computerworld.com/article/3024404/worst-most-common-passwords-for-the-last-5-years.html

The ease and stress of Google Passwords

I have a large amount of account across various websites like Hulu, Netflix, Amazon, some resume websites, game websites and many many more. It is difficult to remember my username and password for EVERY single one of these websites and Google Passwords does an amazing job of keeping track of these details for me.

Eventually it did start to worry me when I could no longer remember important account information for websites such as LinkedIn and Facebook. I realized I relied too heavily on Google passwords to do everything for me. Then there were times when I updated my information but Google didn’t automatically update the autofill information. This lead to many cycles of password resetting.

It dawned on me to create a Python script where I can input this information and store it in some text file. Now I have a good feeling that if I struggle with this issue, there might be others who have the same problem. The best part about programming is that I have the ability to help solve some common problems! I decided to make a GUI application that others can use to store their account information if they’d like. The actual coding did not take very long for this project but it was my first time making a GUI and I had to read the documentation for it.

The full code can be found in my GitHub:

Python GUI

There are many different modules that can help you create GUIs in Python such as:

  • Tkinter
  • PyQt5
  • Kivy and many more.

Tkinter is a very popular choice as it is very simple while PyQt5 and Kivy can produce higher level GUIs. I chose to go with PyQt5 because if I plan on making more GUIs in the future then I’ll only benefit from learning it now.

The end product does not look that appealing but it gets the job done.

The app is pretty straightforward, a user inputs information for all three fields and then it’ll pop up in the same window, while saving it to a JSON file called ‘passwords’.

There are two ways you can decide to create a PyQt5 GUI application. You can either hard code the widgets or use the Designer application provided when you install PyQt5. The application allows you to drag and drop widgets, then save the file and convert it into Python code to run in a script.

I chose the ‘harder’ route by hard coding the entire GUI because I didn’t really understand the code when I create one using the Designer application. I felt hard coding it would give me more control over the GUI and its components.

The layout is fairly simple I don’t really need to add much to it beside some text fields, submit button and labels. The difficult part was figuring out how to save this information to a file and then adding it to the bottom of the GUI.

Data Storage

I felt that storing the information in a JSON file in the format:

data = {‘website’:[username,password],}

Would be beneficial because it’ll allow for easy searching for certain websites just in case the user needs to update or delete information.

Now we have to figure out what to do when the user hits the submit button.

User Interaction

When the user hits the submit button a couple things have to happen:

  1. We need to pull the contents from the text fields and put them in respective variables.
  2. Check if there are any missing fields, if so don’t save anything.
  3. Save the user information in the dictionary shown above.
  4. Update the GUI to display the new user information.

Pulling the contents from the text fields are pretty simple and with logic we can perform step 1 and 2:

The way for us to update the GUI is with text labels. We can create three separate labels for the username,password and website then push them into a vertical box so we can stack each new input.

The arguments for add_label are the username,password and website that we return from get_information. The method add_label unpacks the tuple, user_info, to create three labels. These labels are then pushed into a horizontal box which allows for equal separation of the labels. Each horizontal box is going to be one line of user information. These horizontal boxes will then be pushed into a larger vertical box which will stack these horizontal boxes vertically. This is essentially how we’ll update our GUI.

Now we have to save our information somewhere and I think it’ll be best to save it after the click.

This function will try to create our horizontal and vertical boxes upon clicking the submit button. If it is unable to that means the get_information method returned None because an input field was left blank. If the GUI was updated successfully the information is saved to the JSON file ‘passwords’ that is created in the same directory as the executable file. The fields are then erased of the previous inputs.

Reading and displaying user information

Everything is fine and dandy once you open the GUI and input some information. But now what happens if you close and then reopen the app? I haven’t create a method yet to display the user information from the passwords.json file!

What do we need:

  1. A method to check for the passwords.json file and create it if it’s not there.
  2. Read the contents of the json file.
  3. Convert the dictionary into labels to display the information.

The methods to save and read the information are straightforward. In the read_password method I added a check to create the file ‘passwords.json’ if it does not exist. The method to turn the dictionary into labels involves looping through the dictionary and creating loops for each key.

This method here will try to loop over the dictionary, info. It will not be able to loop over it if the user has not entered any information yet. Now we have all our code to create the GUI, it’s time to put everything together when the class is initialized.

Code to create our GUI

The PyQt5 code involves inheriting from the super class QtWidgets.QWidget and calling the constructor for that class. Then following is calling the constructor for our GUI. The code to read our JSON and create the labels are found near the bottom because I wanted the GUI to load first. If that code were higher up and there was a bug reading the files, I would imagine that the GUI might not load properly. I turned this Python script into an executable file so anyone can run it.

All of your information is stored directly onto your computer in the same directory as the exe file.

The full code can be found in my GitHub repository:

Moving Forward

There is no function to edit or delete user information so that will be the next addition!

--

--

Kristian Roopnarine

Full Stack Engineer sharing tips and tricks for anyone learning to program. Connect with me on LinkedIn : https://www.linkedin.com/in/kristianroopnarine/