DEV Community

Palak Hirave
Palak Hirave

Posted on

Day 29 : Password Manager

This is a local version of Google's Password Manager, in which the user has to manually input all of their passwords, which then gets saved in a text file to view later.

Screenshots


Main screen, the email field is pre-set with your email however you can change it


Confirmation popup


Error message if you try to add a new entry but have blank fields


All entires get saved into a text file

Program

from  tkinter import *
from tkinter import messagebox
from random import choice, randint, shuffle
import pyperclip
#---------------------------- PASSWORD GENERATOR ------------------------------- #
def generate_password():
    letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
    numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']

    password_letters = [choice(letters) for _ in range(randint(8, 10))]
    password_symbols = [choice(symbols) for _ in range(randint(2, 4))]
    password_numbers = [choice(numbers) for _ in range(randint(2, 4))]

    password_list = password_letters + password_symbols + password_numbers

    shuffle(password_list)

    password = "".join(password_list)
    password_entry.insert(0, password)
    pyperclip.copy(password)
# ---------------------------- SAVE PASSWORD ------------------------------- #
def save_data():
    website = website_entry.get()
    email = email_entry.get()
    password = password_entry.get()

    if len(website) == 0 or len(email) == 0 or len(password) == 0:
        messagebox.showerror("Error", "Please fill in all fields")
    else:
        is_ok = messagebox.askokcancel(title=website, message=f"Here are the details: \nPassword: {password}"
                                                      f"\nEmail: {email} \n Is it okay to save?")
        if is_ok:
            with open("data.txt", "a") as file:
                file.write(f"Website: {website} | Email: {email} | Password: {password}\n")
                website_entry.delete(0, END)
                password_entry.delete(0, END)

# ---------------------------- UI SETUP ------------------------------- #
window = Tk()
window.title("Password Manager")
window.minsize(500, 250)
window.config(padx=30, pady=30)

canvas = Canvas(width=200, height=200)
logo = PhotoImage(file="logo.png")

canvas.create_image(100, 100, image=logo)
canvas.grid(column=1, row=0)

website_label = Label(window, text="Website:")
website_label.grid(column=0, row=1)
website_entry = Entry(width=50)
website_entry.focus()
website_entry.grid(column=1,row=1, columnspan=2)

email_label = Label(window, text="Email/Username:")
email_label.grid(column=0, row=2)
email_entry = Entry(width=50)
email_entry.insert(0,"example@gmail.com")
email_entry.grid(column=1,row=2, columnspan=2)

password_label = Label(window, text="Password:")
password_label.grid(column=0, row=3)
password_entry = Entry(width=50)
password_entry.grid(column=1,row=3, padx=5, sticky="w")
password_button = Button(text="Generate Password", command=generate_password)
password_button.grid(column=1, row=3, padx=5,sticky="e")

add_button = Button(text="Add", width=42, command=save_data)
add_button.grid(column=1, row=4, columnspan=2)

window.mainloop()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)