-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
89 lines (75 loc) · 3.58 KB
/
main.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
#This file is for taking mysql_credentials which will be used in other files...
try:
import pbkdf2,pymysql,pyaes,PIL,pyperclip
from tkinter import *
import os.path
import Signup_system
import pymysql
from tkinter import messagebox
from PIL import ImageTk, Image
except :
import install_dependencies
from tkinter import *
import os.path
import Signup_system
import pymysql
from tkinter import messagebox
from PIL import ImageTk,Image
def main():
mysql_login=MYSQL_LOGIN()
class MYSQL_LOGIN:
def __init__(self):
self.check_file=os.path.join(os.path.abspath(os.path.dirname(__file__)),"mysqlcredentials.txt")
self.check_in_file()
def check_in_file(self):
if not os.path.exists(self.check_file):
self.mysql_login()
else:
with open(self.check_file,"r") as f:
output=[word.strip("\n") for word in f.readlines()]
Signup_system.main()
def mysql_login(self):
self.root=Tk()
self.root.title("MySQL Credentials")
self.root.geometry("300x300+500+100")
a = ImageTk.PhotoImage(file="pictures_1/mysql_hosting.png")
self.root.iconphoto(False, a)
credential_title=Label(self.root,text="MYSQL CREDENTIALS",fg="black",bg="cyan",relief=GROOVE,font=("times new roman",17,"bold")).pack(side=TOP,fill=X)
host_l = Label(self.root, text="Enter hostname:" ,bg="Lightcyan2").place(x=5,y=40)
port_l = Label(self.root, text="Enter port_number:",bg="Lightcyan2").place(x=5,y=70)
user_l = Label(self.root, text="Enter username:",bg="Lightcyan2").place(x=5,y=100)
pass_l = Label(self.root, text="Enter password: ",bg="Lightcyan2").place(x=5,y=130)
self.host_e=Entry(self.root,width=20,bg="white")
self.host_e.insert(0,"localhost")
self.port_e=Entry(self.root,width=20,bg="white")
self.port_e.insert(0,"3306")
self.user_e=Entry(self.root,width=20,bg="white")
self.user_e.insert(0,"root")
self.pass_e=Entry(self.root,width=20,bg="white",show="*")
self.pass_e.insert(0,"")
self.host_e.place(x=120,y=40)
self.port_e.place(x=120,y=70)
self.user_e.place(x=120,y=100)
self.pass_e.place(x=120,y=130)
# Caution=Label(self.root,text="Password entry empty if there is no password!")
exit_btn=Button(self.root,text="Exit",bg="red",fg="black",font=("times new roman",12,"bold"),relief=GROOVE,command=self.root.destroy).place(x=250,y=255)
check_btn=Button(self.root,text="Check",bg="dodger blue",fg="black",font=("times new roman",15,"bold"),relief=RAISED,command=self.write_details).place(x=110,y=180)
self.root.mainloop()
def check_connection(self):
try:
con=pymysql.connect(host=self.host_e.get(),port=int(self.port_e.get()),user=self.user_e.get(),passwd=self.pass_e.get())
return True
except Exception as es:
return False
def write_details(self):
if not self.check_connection():
messagebox.showerror("Error","Invalid Details Given!",parent=self.root)
else:
with open(self.check_file,"w") as f:
f.write(self.host_e.get()+"\n"+self.port_e.get()+"\n"+self.user_e.get()+"\n"+self.pass_e.get()+"\n")
f.close()
messagebox.showinfo("Congrats","Correct details given!",parent=self.root)
self.root.destroy()
Signup_system.main()
if __name__ == '__main__':
main()