Skip to content

Commit 7c1fb64

Browse files
committed
Master password functionality added
1 parent 3c309b3 commit 7c1fb64

File tree

1 file changed

+60
-47
lines changed

1 file changed

+60
-47
lines changed

Password-Manager-GUI/passwords.py

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from tkinter import *
2-
from tkinter import messagebox
2+
from tkinter import messagebox,simpledialog
33
import sqlite3
44
from sqlite3 import Error
5+
import sys
6+
7+
# Store Master password
8+
master_password = sys.argv[1]
59

610
# Function to connect to the SQL Database
711
def sql_connection():
@@ -11,28 +15,29 @@ def sql_connection():
1115
except Error:
1216
print(Error)
1317

14-
# Function to create table
18+
# Function to create table
1519
def sql_table(con):
1620
cursorObj = con.cursor()
17-
cursorObj.execute("CREATE TABLE IF NOT EXISTS passwords(website text, username text, pass text)")
21+
cursorObj.execute(
22+
"CREATE TABLE IF NOT EXISTS passwords(website text, username text, pass text)")
1823
con.commit()
1924

2025
# Call functions to connect to database and create table
2126
con = sql_connection()
2227
sql_table(con)
2328

24-
#Create submit function for database
29+
# Create submit function for database
2530
def submit(con):
2631
cursor = con.cursor()
27-
#Insert Into Table
28-
if website.get()!="" and username.get()!="" and password.get()!="":
32+
# Insert Into Table
33+
if website.get() != "" and username.get() != "" and password.get() != "":
2934
cursor.execute("INSERT INTO passwords VALUES (:website, :username, :password)",
30-
{
31-
'website': website.get(),
32-
'username': username.get(),
33-
'password': password.get()
34-
}
35-
)
35+
{
36+
'website': website.get(),
37+
'username': username.get(),
38+
'password': password.get()
39+
}
40+
)
3641
con.commit()
3742
# Message box
3843
messagebox.showinfo("Info", "Record Added in Database!")
@@ -48,29 +53,36 @@ def submit(con):
4853
# Create Query Function
4954
def query(con):
5055

51-
#set button text
52-
query_btn.configure(text="Hide Records", command=hide)
53-
54-
cursor = con.cursor()
55-
56-
#Query the database
57-
cursor.execute("SELECT *, oid FROM passwords")
58-
records = cursor.fetchall()
59-
#print(records)
60-
61-
p_records = " Id \t\t Website \t\t Username \t\t Password\n"
62-
for record in records:
63-
p_records += str(record[3])+ "\t\t" +str(record[0])+ "\t\t" + str(record[1])+ "\t\t" + str(record[2]) + "\n"
64-
#print(record)
65-
66-
query_label['text'] = p_records
67-
# Commit changes
68-
con.commit()
56+
password = simpledialog.askstring("Password","Enter Master Password")
57+
if(password == master_password):
58+
# set button text
59+
query_btn.configure(text="Hide Records", command=hide)
60+
cursor = con.cursor()
61+
# Query the database
62+
cursor.execute("SELECT *, oid FROM passwords")
63+
records = cursor.fetchall()
64+
65+
p_records = 'ID'.ljust(10)+ 'Website'.ljust(40)+'Username'.ljust(70)+'Password'.ljust(100)+'\n'
66+
67+
for record in records:
68+
single_record = ""
69+
single_record += (str(record[3]).ljust(10) +
70+
str(record[0]).ljust(40)+str(record[1]).ljust(70)+str(record[2]).ljust(100))
71+
single_record += '\n'
72+
# print(single_record)
73+
p_records += single_record
74+
query_label['text'] = p_records
75+
# Commit changes
76+
con.commit()
77+
p_records = ""
78+
79+
else:
80+
messagebox.showinfo("Failed!", "Authentication failed!")
6981

70-
#Create Function to Hide Records
82+
# Create Function to Hide Records
7183
def hide():
7284
query_label['text'] = ""
73-
query_btn.configure(text="Show Records", command=lambda:query(con))
85+
query_btn.configure(text="Show Records", command=lambda: query(con))
7486

7587

7688
root = Tk()
@@ -80,38 +92,39 @@ def hide():
8092
root.maxsize(600, 400)
8193

8294
frame = Frame(root, bg="#774A9F", bd=5)
83-
frame.place(relx=0.50, rely=0.50, relwidth=0.98, relheight=0.45, anchor = "n")
95+
frame.place(relx=0.50, rely=0.50, relwidth=0.98, relheight=0.45, anchor="n")
8496

85-
#Create Text Boxes
97+
# Create Text Boxes
8698
website = Entry(root, width=30)
87-
website.grid(row=1, column=1, padx=20,pady=5)
99+
website.grid(row=1, column=1, padx=20, pady=5)
88100
username = Entry(root, width=30)
89-
username.grid(row=2, column=1, padx=20,pady=5)
101+
username.grid(row=2, column=1, padx=20, pady=5)
90102
password = Entry(root, width=30)
91-
password.grid(row=3, column=1, padx=20,pady=5)
103+
password.grid(row=3, column=1, padx=20, pady=5)
92104

93-
#Create Text Box Labels
94-
website_label = Label(root, text = "Website:")
105+
# Create Text Box Labels
106+
website_label = Label(root, text="Website:")
95107
website_label.grid(row=1, column=0)
96-
username_label = Label(root, text = " Username:")
108+
username_label = Label(root, text=" Username:")
97109
username_label.grid(row=2, column=0)
98-
password_label = Label(root, text = "Password:")
110+
password_label = Label(root, text="Password:")
99111
password_label.grid(row=3, column=0)
100112

101113

102-
#Create Buttons
103-
submit_btn = Button(root, text = "Add Password",command = lambda: submit(con))
104-
submit_btn.grid(row = 5, column=1, pady=5, padx=15, ipadx=35)
105-
query_btn = Button(root, text = "Show All",command = lambda: query(con))
114+
# Create Buttons
115+
submit_btn = Button(root, text="Add Password", command=lambda: submit(con))
116+
submit_btn.grid(row=5, column=1, pady=5, padx=15, ipadx=35)
117+
query_btn = Button(root, text="Show All", command=lambda: query(con))
106118
query_btn.grid(row=6, column=1, pady=5, padx=5, ipadx=35)
107119

108-
#Create a Label to show stored passwords
120+
# Create a Label to show stored passwords
109121
global query_label
110122
query_label = Label(frame, anchor="nw", justify="left")
111123
query_label.place(relwidth=1, relheight=1)
112124

113125
def main():
114126
root.mainloop()
115127

128+
116129
if __name__ == '__main__':
117-
main()
130+
main()

0 commit comments

Comments
 (0)