forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpasswords.py
143 lines (107 loc) · 3.89 KB
/
passwords.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from tkinter import *
from tkinter import messagebox, simpledialog
import sqlite3
from sqlite3 import Error
import sys
# Store Master password
master_password = sys.argv[1]
# Function to connect to the SQL Database
def sql_connection():
try:
con = sqlite3.connect('passwordManager.db')
return con
except Error:
print(Error)
# Function to create table
def sql_table(con):
cursorObj = con.cursor()
cursorObj.execute(
"CREATE TABLE IF NOT EXISTS passwords(website text, username text, pass text)")
con.commit()
# Call functions to connect to database and create table
con = sql_connection()
sql_table(con)
# Create submit function for database
def submit(con):
cursor = con.cursor()
# Insert Into Table
if website.get() != "" and username.get() != "" and password.get() != "":
cursor.execute("INSERT INTO passwords VALUES (:website, :username, :password)",
{
'website': website.get(),
'username': username.get(),
'password': password.get()
}
)
con.commit()
# Message box
messagebox.showinfo("Info", "Record Added in Database!")
# After data entry clear the text boxes
website.delete(0, END)
username.delete(0, END)
password.delete(0, END)
else:
messagebox.showinfo("Alert", "Please fill all details!")
# Create Query Function
def query(con):
password = simpledialog.askstring("Password", "Enter Master Password")
if(password == master_password):
# set button text
query_btn.configure(text="Hide Records", command=hide)
cursor = con.cursor()
# Query the database
cursor.execute("SELECT *, oid FROM passwords")
records = cursor.fetchall()
p_records = 'ID'.ljust(10) + 'Website'.ljust(40) + \
'Username'.ljust(70)+'Password'.ljust(100)+'\n'
for record in records:
single_record = ""
single_record += (str(record[3]).ljust(10) +
str(record[0]).ljust(40)+str(record[1]).ljust(70)+str(record[2]).ljust(100))
single_record += '\n'
# print(single_record)
p_records += single_record
query_label['text'] = p_records
# Commit changes
con.commit()
p_records = ""
else:
messagebox.showinfo("Failed!", "Authentication failed!")
# Create Function to Hide Records
def hide():
query_label['text'] = ""
query_btn.configure(text="Show Records", command=lambda: query(con))
root = Tk()
root.title("Password Manager")
root.geometry("500x400")
root.minsize(600, 400)
root.maxsize(600, 400)
frame = Frame(root, bg="#774A9F", bd=5)
frame.place(relx=0.50, rely=0.50, relwidth=0.98, relheight=0.45, anchor="n")
# Create Text Boxes
website = Entry(root, width=30)
website.grid(row=1, column=1, padx=20, pady=5)
username = Entry(root, width=30)
username.grid(row=2, column=1, padx=20, pady=5)
password = Entry(root, width=30)
password.grid(row=3, column=1, padx=20, pady=5)
# Create Text Box Labels
website_label = Label(root, text="Website:")
website_label.grid(row=1, column=0)
username_label = Label(root, text=" Username:")
username_label.grid(row=2, column=0)
password_label = Label(root, text="Password:")
password_label.grid(row=3, column=0)
# Create Buttons
submit_btn = Button(root, text="Add Password", command=lambda: submit(con))
submit_btn.grid(row=5, column=1, pady=5, padx=15, ipadx=35)
query_btn = Button(root, text="Show All", command=lambda: query(con))
query_btn.grid(row=6, column=1, pady=5, padx=5, ipadx=35)
# Create a Label to show stored passwords
global query_label
query_label = Label(frame, anchor="nw", justify="left")
query_label.place(relwidth=1, relheight=1)
def main():
root.mainloop()
if __name__ == '__main__':
main()