-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmanager.py
More file actions
157 lines (127 loc) · 5.28 KB
/
manager.py
File metadata and controls
157 lines (127 loc) · 5.28 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
try:
from tkinter import *
from tkinter import ttk
except ImportError:
from Tkinter import *
import ttk
import Add
import hashlib
import os
import encode
import List
import Search
LARGE_FONT = ("Verdana", 13)
BUTTON_FONT = ("Sans-Serif", 10, "bold")
class Login(Tk):
"""docstring for Login"""
def __init__(self, *args):
Tk.__init__(self, *args)
'''Needs update'''
if os.name == 'nt':
Tk.iconbitmap(self, default='icon.ico')
Tk.wm_title(self, "Password Manager")
self.state = {
"text": "Login to access password database.", "val": False
}
if encode.password:
self.addLoginFrame()
else:
self.addRegisterFrame()
# Adding frames
def addLoginFrame(self, *kwargs):
login = Frame(self, padx=2, pady=2, bd=2)
login.pack()
loginLabel = Label(login, text=self.state['text'],
bd=10, font=LARGE_FONT, width=30)
loginLabel.grid(row=0, columnspan=3)
entry = ttk.Entry(login, show="*")
entry.grid(row=1, column=1, pady=3)
# _ marks an unused variable; used for lambda compatibility
# Bind event for when enter is pressed in the Entry
entry.bind('<Return>', lambda _: self.checkPwd(
login, label=loginLabel, entry=entry, btn=submitBtn))
entry.focus_set()
s = ttk.Style()
s.configure("Submit.TButton", font=BUTTON_FONT)
submitBtn = ttk.Button(login, text="Submit", style="Submit.TButton",
command=lambda: self.checkPwd(
login, label=loginLabel, entry=entry,
btn=submitBtn))
submitBtn.grid(row=2, column=1, pady=3)
"""Kwargs = loginLabel, password entry, and submit button"""
def checkPwd(self, frame, **kwargs):
chk = kwargs['entry'].get()
# if passwords match
if hashlib.md5(chk).hexdigest() == encode.password:
self.state['text'] = "Logged In"
self.state['val'] = True
# Using .config() to modift the args
kwargs['label'].config(text=self.state['text'])
kwargs['entry'].config(state=DISABLED)
kwargs['btn'].config(state=DISABLED)
# adding buttons
self.addConfigBtn(frame)
# If passwords don't match
else:
kwargs['label'].config(text=self.state['text'] + "\nTry Again!!!")
def addConfigBtn(self, login):
# configured buttons
# btnList = (addBtn, listBtn, getBtn)
# Creating temp references to images using temp1,2,3 so as to disallow
# garbage collection problems
btnList = ["Add", "List", "Search"]
btnCmdList = [lambda: Add.AddWindow(self),
lambda: List.ListWindow(self),
lambda: Search.SearchWindow(self)]
f = [] # Frames array
img = [] # image array
self.temp = [] # temp array
for i in xrange(3):
f.append(Frame(login, padx=2, width=50, height=50))
f[i].grid(row=3, column=i)
img.append(PhotoImage(
file=btnList[i] + ".gif", width=48, height=48))
self.temp.append(img[i])
ttk.Button(f[i], image=img[i], text=btnList[i], compound="top",
style="Submit.TButton",
command=btnCmdList[i]).grid(sticky="NWSE")
def addRegisterFrame(self, *arg):
register = Frame(self, padx=2, pady=2, bd=2)
register.pack()
info = "Register with a password\nTo start using the manager"
registerLabel = Label(register, text=info,
bd=10, font=LARGE_FONT, width=30)
registerLabel.grid(row=0, columnspan=3)
entry = ttk.Entry(register, show="*")
entry.grid(row=1, column=1, pady=3)
entry.focus_set()
entryChk = ttk.Entry(register, show="*")
entryChk.grid(row=2, column=1, pady=3)
entryChk.bind('<Return>', lambda _: self.register(register,
entry, entryChk))
s = ttk.Style()
s.configure("Submit.TButton", font=BUTTON_FONT)
submitBtn = ttk.Button(register, text="Register",
style="Submit.TButton",
command=lambda: self.register(register,
entry, entryChk))
submitBtn.grid(row=3, column=1, pady=3)
def register(self, frame, *pwd):
# pwd is a list containing password inputs
if pwd[0].get() == pwd[1].get():
encode.password = hashlib.md5(pwd[0].get()).hexdigest()
# Saving password for future use.
open(".pwd", "w").write(encode.password)
frame.destroy()
self.addLoginFrame()
else:
error = "Passwords dont match!!\nTry again."
errorLabel = Label(frame, text=error,
bd=10, font=("Verdana", 11), fg="red")
errorLabel.grid(row=4, column=1, pady=3)
# Removing previosly entered Passwords
for wid in pwd:
wid.delete(0, 'end')
if __name__ == '__main__':
new = Login()
new.mainloop()