-
Notifications
You must be signed in to change notification settings - Fork 0
/
changepass.py
76 lines (61 loc) · 2.99 KB
/
changepass.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
from tkinter import *
from tkinter import messagebox, ttk
import pymysql
import parent
class ChangePass:
def __init__(self, myframe):
self.root = Toplevel(myframe)
self.root.title("Change Password")
self.root.geometry("800x450+260+110")
self.root.configure(background="#ffe5b4")
lb4=Label(self.root, text="User Name")
lb1=Label(self.root, text="Current Password")
lb2=Label(self.root, text="New Password")
lb3=Label(self.root, text="Confirm Password")
self.unamebox = Entry(self.root)
self.currentpassbox = Entry(self.root)
self.unamebox.focus_set()
self.newpassbox = Entry(self.root,show="*")
self.confirmpassbox = Entry(self.root,show="*")
create_btn=Button(self.root, text="Change Password", command=self.changepassword)
self.root.resizable(0, 0)
lb1.configure(background="#ffe5b4")
lb2.configure(background="#ffe5b4")
lb3.configure(background="#ffe5b4")
lb4.configure(background="#ffe5b4")
lb4.place(x=50,y=50)
lb1.place(x=50,y=100)
lb2.place(x=50,y=150)
lb3.place(x=50,y=200)
self.unamebox.place(x=200, y=50)
self.currentpassbox.place(x=200,y=100)
self.newpassbox.place(x=200,y=150)
self.confirmpassbox.place(x=200,y=200)
create_btn.place(x=200,y=250)
self.root.mainloop()
def changepassword(self):
if self.newpassbox.get() == self.confirmpassbox.get():
try:
myobj=pymysql.connect(host="localhost", user="root",
password="", db="office")
try:
with myobj.cursor() as myconn:
affected_rows = myconn.execute("update usertable "
"set pass=%s "
"where uname=%s "
"and pass=%s",
(self.confirmpassbox.get(), self.unamebox.get(), self.currentpassbox.get()))
myobj.commit()
if affected_rows > 0:
messagebox.showinfo("Success", "Password updated Successfully", parent=self.root)
else:
messagebox.showwarning("Warning", "Old Password is wrong", parent=self.root)
except Exception as ex:
messagebox.showerror("Error Occured", "Error occured in Query due to " + str(ex))
finally:
myobj.close()
self.root.destroy()
except Exception as ex:
messagebox.showerror("Error Occured", "Error occured in Connection due to " + str(ex))
else:
messagebox.showwarning("Warning", "Password does not match")