Password Manager Application in Python

Introduction: This application will help to generate a very strong password, save passwords and find whenever is needed. 

This is a very simple application builted in Python. It is very suitable for python beginner learners and students who want to learn python and useful for college projects.

This application also has Copied to clipboard Feature, in which, while generating a new password, you don't have to copy it. It automatically saves in your clipboard, you can directly paste wherever you need.



CODE:

from tkinter import *
from tkinter import messagebox
from random import randint, choice, shuffle
import pyperclip
import json


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 GENERATOR ------------------------------- #
def generate_pass():
password_letter = [choice(letters) for _ in range(randint(8, 10))]
password_symbol = [choice(symbols) for _ in range(randint(2, 4))]
password_number = [choice(numbers) for _ in range(randint(2, 4))]

password_list = password_number + password_symbol + password_letter
shuffle(password_list)
new_pass = "".join(password_list)
password_field.delete(0, END)
password_field.insert(0, new_pass)
pyperclip.copy(new_pass)

# ---------------------------- SAVE PASSWORD ------------------------------- #
def save_data():
email = email_field.get().lower()
website = website_field.get()
password = password_field.get()
if email == "" or password == "" or website == "":
messagebox.showwarning(title="Ooops", message="Check fields,\none or more fields are empty!")
else:
is_confirm = messagebox.askyesno(title="Are you sure to insert these data?", message=f"Email:{email}\n password:{password}\n\n Click Yes to insert")
if is_confirm:
data = {
website: {
"email": email,
"password": password
}
}
try:
with open("data.json", "r") as file:
new_data = json.load(file)
new_data.update(data)
except FileNotFoundError:
with open("data.json", "w") as c_file:
json.dump(data, c_file, indent=4)
else:
with open("data.json", "w") as u_file:
json.dump(new_data, u_file, indent=4)

clear_fields()


def clear_fields():
website_field.delete("0","end")
password_field.delete("0","end")


# ---------------------------- Search Function ------------------------------- #
def search():
search_key = website_field.get().lower()
try:
with open("data.json", "r") as file:
search_result = json.load(file)
except FileNotFoundError:
messagebox.showwarning(title="File not found", message="Is this the first time you open the appliceation?\nFirst insert some data!")
else:
if search_key in search_result:
s_password = search_result[search_key]["password"]
s_username = search_result[search_key]["email"]
messagebox.showinfo(title="Search Result", message=f"Website: {search_key}\nUsername: {s_username} \nPassword: {s_password}")
else:
messagebox.showinfo(title="Search Result", message="No data found..")




# ---------------------------- UI SETUP ------------------------------- #

window = Tk()
window.title("Password Manager")
window.config(padx=50, pady=50)



canvas = Canvas(height=200, width=189)
image = PhotoImage(file="logo.png")
canvas.create_image(100, 100, image=image)
canvas.grid(row = 1, column= 1, sticky="w")


website = Label(text="Website", font=("Helvetica", 15))
website.grid(row=2, column=0)

website_field = Entry(width=20)
website_field.focus()
website_field.grid(row=2, column=1, sticky="w")


search_btn = Button(text="Search", width=8, command=search)
search_btn.grid(row=2, column=1, sticky="e")


email = Label(text="Email\\Username", font=("Helvetica", 15))
email.grid(row=3, column=0)

email_field = Entry(width=30)
email_field.insert(0, "nandalalsun@gmail.com")
email_field.grid(row=3, column=1)

password = Label(text="Password", font=("Helvetica", 15))
password.grid(row=4, column=0)

password_field = Entry(width=20, justify="left")
password_field.grid(row=4, column=1, sticky="w")

generate_btn = Button(text="Generate", width=8, command=generate_pass)
generate_btn.grid(row=4, column=1, sticky="e")

add_btn = Button(text="Add", width=31, command=save_data)
add_btn.grid(row=5, column=1)

window.mainloop()





LOGO

filename: logo.png
file dimension: 200 x 189




Comments

Popular posts from this blog

Where Does Intelligence Begin?

Random is not actually indeterministic, its hard to calculate.

Existence Game