If You’re the Type of Person, Just Like Me, Who Has Very Long and Complex Passwords That You Can’t Remember, and You’ve Saved Them All in a Notepad File but Now Can’t Easily Find Them, I’ve Created a Small Program Where You Can Effortlessly Identify the Passwords for the Websites Where You Have Accounts on the Internet.
Having different passwords for each site is part of the basics of internet security because if one site is compromised, hackers can use your password to authenticate themselves on other sites where you have accounts if your password is always the same. In the past, I’ve had my passwords exposed on certain small and unimportant websites when they were accessed without authorization by certain individuals.
Because I use different passwords for each site, consisting of numbers, letters, and special characters, the hackers couldn’t do anything with them. The most they were able to do was send me spam/scam emails, attempting to deceive me into doing various things. That’s why it’s good to have different passwords for each site where you have an internet account, and these passwords should be as long and difficult as possible, using lowercase letters, uppercase letters, numbers, and special characters, typed randomly.
Unfortunately, if you’re like me and you save all your passwords in a Notepad file, you know that as the years go by and you have more and more accounts on various websites, that password file will become huge, and sometimes it will take you minutes to identify a password for a certain site that you haven’t visited in a long time and that you didn’t save to have the browser you’re using, such as Google Chrome, remember it for you.
For such moments, there are professional password managers that encrypt the passwords, some even included in the security suites provided by major cybersecurity companies. In addition to password managers, which represent a fairly secure way to save your passwords on your personal computer, there are also other less secure methods, such as using an Excel file where you have the search function for what you want to look for in it.
But why to do things in a simple way when we can complicate them? Instead of copy-pasting my saved passwords from the Notepad file into a Microsoft Excel file, which are very many and sometimes it’s difficult for me to identify the one I need, I thought it would be better to create a small program written in Python to help me quickly identify a site and its password when I need it. From a simple program with just password search, I started adding other functions and making it look more stylish with the help of the “Pretty Tables” library.
My password manager, written in Python, has the following functions: login password (I’ve set it to “test1” but you can change it from the field MASTER_PASSWORD = “test1”), add a Website/Username/Password, search for a website and display its username and password, edit a Website/Username/Password, delete an entry, list all Websites/Usernames/Passwords, and Exit.
Also, I have implemented the following features in my password manager: if you enter the wrong password three times in a row, the program will shut down/exit; you can use the search function without typing the full name of the website, but just a few letters of it, and all the domains containing those letters will be displayed; I have added protection when deleting an entry, requiring confirmation with y/n if you really want to delete it; when using option 5 to list all the websites, they will be displayed in alphabetical order, not in the order you added them in the text file.
Obviously, this program can only be used if you are the only one who has access to your computer because if multiple people use your PC, it is not a secure way to save your passwords.
The program creates a Notepad file called “passwords.txt”, where it saves the login data: website, username, and password. That file can be viewed by anyone who has access to your computer, so I repeat: it is quite safe to use it if you are the only person who has access to the PC where you save your passwords. You can choose to hide the “passwords.txt” Notepad file, but this method, as well as the login password in the program, are only there for beginners because a person with basic computer knowledge who uses your personal PC will immediately know how to view your passwords, so use the program with caution, but… if you also save your passwords in a Notepad file, just like me, I think my program is a step forward, even if only because now you can easily find the passwords for different websites.
What steps do you need to follow to use this small password manager written in Python:
First, you need to install Python from python.org. It would be good to install it somewhere easily accessible, and I’ll explain why shortly, such as in C: on your computer. After installing Python, we need to add the “Pretty Tables” library because without it, the script will throw an error and close. Pretty Tables makes the password tables look better when we choose option 5 to list all passwords (see the print screen).
Before adding the Pretty Tables library in Python, we need to make Windows understand the “pip” command that we’ll use later by adding the path to the “Python Scripts” folder. I’m using Windows 11, so I’ll explain how to do this on this operating system, but it shouldn’t be much different on other versions of Microsoft’s operating system. In the Windows search menu, we search for “Edit the system environment variables,” then click on “Environment Variables,” and under “System Variables,” we scroll down to “Path” and click the “Edit” button.
After that, we select “New” and enter the path to the “Python Scripts” folder. That’s why I mentioned installing Python in C: to make it easier to reach the path “C:\Python39\Scripts”. We add this variable, click OK, and close all windows.
Now we just need to install the Pretty Tables library. To install Pretty Tables, we open the Start menu and search for “Command Prompt” or “cmd”. Right-click on the “Command Prompt” option in the search results and select “Run as administrator.” In the command window that appears, we enter the command “pip install prettytable” (without quotes) and press Enter. We wait a few moments until the installation is completed.
Now everything should be in order, and all you have left to do is copy the Python script below and save it in a Notepad file, then give it a name, and the extension should be “.py”. For example, you can name it 1.py and double click it to open it.
import os
PASSWORD_FILE = “passwords.txt”
MASTER_PASSWORD = “test1”
def get_master_password():
attempts = 0
while attempts < 3:
password = input(“Enter master password: “)
if password == MASTER_PASSWORD:
return True
else:
attempts += 1
print(f”Incorrect password. {3 – attempts} attempts left.”)
print(“Too many incorrect attempts. Exiting program.”)
return False
def add_password():
website = input(“Enter website: “)
username = input(“Enter username: “)
password = input(“Enter password: “)
with open(PASSWORD_FILE, “a”) as f:
f.write(f”Website: {website}\nUsername: {username}\nPassword: {password}\n\n”)
print(“Password saved successfully.”)
from prettytable import PrettyTable
def search_password():
website = input(“Enter website to search: “)
with open(PASSWORD_FILE, “r”) as f:
passwords = f.readlines()
found_passwords = []
for i in range(0, len(passwords), 4):
if website.lower() in passwords[i].lower():
found_passwords.append([passwords[i+1].strip(), passwords[i+2].strip(), passwords[i].replace(“Website:”, “”).strip()])
if found_passwords:
table = PrettyTable()
table.field_names = [“Website”, “Username”, “Password”]
for password in found_passwords:
table.add_row([password[2], password[0], password[1]])
print(table)
else:
print(“No password found for that website.”)
def edit_password():
website = input(“Enter website to edit password: “)
PASSWORD_FILE = “passwords.txt” # specify the password file name or path here
with open(PASSWORD_FILE, “r”) as f:
passwords = f.read()
if f”Website: {website}” in passwords:
confirmation = input(f”Are you sure you want to edit the password for {website}? (y/n) “)
if confirmation.lower() == “y”:
start_index = passwords.index(f”Website: {website}”)
end_index = passwords.index(“\n\n”, start_index) + 2
old_entry = passwords[start_index:end_index]
old_website = [line.split(“: “)[1] for line in old_entry.splitlines() if line.startswith(“Website”)][0]
new_website = input(f”Enter new website (old website: {old_website}): “)
new_username = input(f”Enter new username (old username: {old_entry.splitlines()[1].replace(‘Username: ‘, ”)}): “)
new_password = input(f”Enter new password (old password: {old_entry.splitlines()[2].replace(‘Password: ‘, ”)}): “)
new_passwords = passwords[:start_index] + f”Website: {new_website}\nUsername: {new_username}\nPassword: {new_password}\n\n” + passwords[end_index:]
with open(PASSWORD_FILE, “w”) as f:
f.write(new_passwords)
print(“Password edited successfully.”)
else:
print(“Edit cancelled.”)
else:
print(“No password found for that website.”)
def delete_password():
website = input(“Enter website to delete password: “)
with open(PASSWORD_FILE, “r”) as f:
passwords = f.read()
if f”Website: {website}” in passwords:
confirmation = input(f”Are you sure you want to delete the password for {website}? (y/n) “)
if confirmation.lower() == “y”:
start_index = passwords.index(f”Website: {website}”)
end_index = passwords.index(“\n\n”, start_index) + 2
new_passwords = passwords[:start_index] + passwords[end_index:]
with open(PASSWORD_FILE, “w”) as f:
f.write(new_passwords)
print(“Password deleted successfully.”)
else:
print(“Deletion cancelled.”)
else:
print(“No password found for that website.”)
def list_passwords():
with open(PASSWORD_FILE, “r”) as f:
passwords = f.readlines()
websites = []
for i in range(0, len(passwords), 4):
websites.append(passwords[i].replace(“Website: “, “”).strip())
websites = sorted(websites)
table = PrettyTable()
table.field_names = [“Website”, “Username”, “Password”]
for website in websites:
for i in range(len(passwords)):
if passwords[i].startswith(f”Website: {website}”):
username = passwords[i + 1].replace(“Username: “, “”).strip()
password = passwords[i + 2].replace(“Password: “, “”).strip()
table.add_row([website, username, password])
print(table)
def main():
if not get_master_password():
return
while True:
print(“\nWhat would you like to do?”)
print(“1. Add a password”)
print(“2. Search for a password”)
print(“3. Edit a password”)
print(“4. Delete a password”)
print(“5. List all passwords”)
print(“6. Exit”)
choice = input(“Enter your choice (1-6): “)
if choice == “1”:
add_password()
elif choice == “2”:
search_password()
elif choice == “3”:
edit_password()
elif choice == “4”:
delete_password()
elif choice == “5”:
list_passwords()
elif choice == “6”:
break
else:
print(“Invalid choice. Please try again.”)
if __name__ == “__main__”:
if not os.path.isfile(PASSWORD_FILE):
with open(PASSWORD_FILE, “w”) as f:
pass
main()
I hope this small password manager written in Python will be helpful to you, and you won’t have to spend minutes searching for a password in your Notepad file where you’ve saved a multitude of passwords for the sites where you have accounts over the years.
P.S: What other methods do you use to manage and secure your passwords? Share your thoughts and experiences in the comments below!