Question - 3
Question - 3
Create a graphical user interface application that can be used to store the
password along with the username. All the data will be encrypted to prove
better security and will be decrypted on demand. Every password will also be
hidden behind a wall which we can enter by using the application password.
SOLUTION:
SOURCE CODE
import tkinter as tk
from tkinter import messagebox, Toplevel, Label, Entry, Button
from cryptography.fernet import Fernet
import json
import os
import hashlib
class PasswordManager:
def __init__(self, root):
self.root = root
self.root.title("Password Manager")
self.root.geometry("400x400")
self.root.configure(bg="#2e3b4e") # Background color for the app
self.app_password = None
self.load_app_password()
def load_app_password(self):
# Load or create a master password
if os.path.exists("app_password.txt"):
with open("app_password.txt", "r") as f:
self.app_password = f.read().strip()
self.main_screen() # Load main screen if password exists
else:
self.setup_password() # Prompt to set password if it doesn't exist
def setup_password(self):
# Create a new window for setting up the application password
setup_window = Toplevel(self.root)
setup_window.title("Setup Application Password")
setup_window.geometry("300x200")
setup_window.configure(bg="#2e3b4e")
def save_setup_password():
password = password_entry.get()
if password:
self.app_password = hash_password(password)
with open("app_password.txt", "w") as f:
f.write(self.app_password)
messagebox.showinfo("Success", "Application password set
successfully!")
setup_window.destroy()
self.main_screen() # Proceed to main screen
else:
messagebox.showerror("Error", "Password cannot be empty")
def main_screen(self):
self.clear_window()
if entered_password == self.app_password:
self.password_vault()
else:
messagebox.showerror("Error", "Incorrect application password")
def password_vault(self):
self.clear_window()
def add_entry(self):
add_window = Toplevel(self.root)
add_window.title("Add New Entry")
add_window.geometry("300x200")
add_window.configure(bg="#2e3b4e")
def save_entry():
username = username_entry.get()
password = password_entry.get()
data[username] = encrypted_password
def view_entries(self):
with open(data_file, 'r') as f:
data = json.load(f)
self.clear_window()
def clear_window(self):
for widget in self.root.winfo_children():
widget.destroy()
if __name__ == "__main__":
root = tk.Tk()
app = PasswordManager(root)
root.mainloop()
OUTPUT