Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import os
- global AdminConfirmation
- AdminConfirmation = False
- def signup():
- global passwordEntry
- global nameEntry
- global roots
- roots = Tk()
- roots.title("Signup")
- prompts = Label(roots, text="Please enter your account details.\n")
- prompts.grid(row=0, column=0, sticky=E)
- nameLabel = Label(roots, text="New Username: ")
- passwordLabel = Label(roots, text="New Password: ")
- nameLabel.grid(row=1, column=0, sticky=W)
- passwordLabel.grid(row=2, column=0, sticky=W)
- nameEntry = Entry(roots)
- passwordEntry= Entry(roots, show="*")
- nameEntry.grid(row=1, column=1)
- passwordEntry.grid(row=2, column=1)
- signupButton = Button(roots, text="Signup", command = FSSignup)
- signupButton.grid(columnspan=2, sticky=W)
- roots.mainloop()
- def AdminSignup():
- global AdminPasswordEntry
- global AdminNameEntry
- global rootsC
- rootsC = Tk()
- rootsC.title("Admin Signup")
- prompts = Label(rootsC, text="Please enter your admin details.\n")
- prompts.grid(row=0, column=0, sticky=E)
- AdminNameLabel = Label(rootsC, text="Username: ")
- AdminPasswordLabel = Label(rootsC, text="Password: ")
- AdminNameLabel.grid(row=1, column=0, sticky=W)
- AdminPasswordLabel.grid(row=2, column=0, sticky=W)
- AdminNameEntry = Entry(rootsC)
- AdminPasswordEntry= Entry(rootsC, show="*")
- AdminNameEntry.grid(row=1, column=1)
- AdminPasswordEntry.grid(row=2, column=1)
- signupButton = Button(rootsC, text="Signup", command = AdminFSignup)
- signupButton.grid(columnspan=2, sticky=W)
- rootsC.mainloop()
- def FSSignup():
- creds = open("loginfile.txt","a") #this is where the student details will be stored
- print(str(nameEntry.get()),passwordEntry.get(),file=creds, sep=",")
- creds.close()
- roots.destroy() #this removes the signup window
- def AdminFSignup():
- Admincreds = open("Adminlogin.txt","a") #this is where the admin details will be stored
- print(AdminNameEntry.get(),AdminPasswordEntry.get(),file=Admincreds, sep=",")
- Admincreds.close()
- rootsC.destroy() #this removes the signup window
- def login():
- global nameLogin
- global passwordLogin
- global rootA
- rootA= Tk()
- rootA.title("Login")
- intruction= Label(rootA, text="Please Login\n")
- intruction.grid(stick=E)
- nameLabel= Label(rootA, text="Username: ")
- passwordLabel= Label(rootA, text="Password: ")
- nameLabel.grid(row=1, sticky=W)
- passwordLabel.grid(row=2,sticky=W)
- nameLogin= Entry(rootA)
- passwordLogin = Entry(rootA, show="*")
- nameLogin.grid(row=1, column=1)
- passwordLogin.grid(row=2, column=1)
- loginButton = Button(rootA, text="Login", command=CheckLogin) #the logic button
- loginButton.grid(columnspan=2, sticky=W)
- AdminSignUp = Button(rootA, text="Admin Signup", fg="black", command=AdminSignup) \
- #the button to remove users
- AdminSignUp.grid(row=4, sticky=W)
- StudentSignUp= Button(rootA, text="Student Signup", command=signup)
- StudentSignUp.grid(row = 4, column = 1)
- #StudentSignUp.grid(columnspan=1,column1)
- #removeUser = Button(rootA, text="Delete User", fg="red", command=AdminCheck) \
- #the button to remove users
- #removeUser.grid(columnspan=4, column = 1)
- rootA.mainloop()
- def CheckLogin():
- #string = nameLogin.get()
- if str(nameLogin.get())[0] == "a":
- Count=0
- Found= False
- Admincreds = open("Adminlogin.txt","r") #this is where the admin details will be stored
- for admins in Admincreds:
- adminFields = admins.split(",")
- r = Tk()
- r.title("D:")
- r.geometry("150x50")
- #rlbl = Label(r, text=((adminFields[1]))
- #rlbl = Label(r, text=((adminFields[0]),(nameLogin.get()),(adminFields[1]),\
- #(passwordLogin.get())))
- rlbl = Label(r, text=((adminFields[0]),(adminFields[1])))
- rlbl.pack()
- r.mainloop()
- if nameLogin.get() == adminFields[0]:
- if passwordLogin.get() == adminFields[1]:
- count+=1
- AdminConfirmation = True
- adminpage()
- rlbl.pack() #pack is just like .grid but used for other things
- r.mainloop()
- else:
- r = Tk()
- r.title("D:")
- r.geometry("150x50")
- rlbl = Label(r, text="\n[!] Invalid Login")
- rlbl.pack()
- r.mainloop()
- Admincreds.close()
- else:
- Count=0
- Found=False
- creds = open("loginfile.txt","r") #this is where the student details will be stored
- for students in creds:
- studentFields = students.split(",")
- if nameLogin.get() == studentFields[0]:
- if passwordLogin.get() == studentFields[1]:
- #checking if data is correct
- count+=1
- r = Tk()
- r.title(":D")
- r.geometry("150x50")
- rlbl = Label(r, text="\n[+] Logged In")
- rlbl.pack() #pack is just like .grid but used for other things
- r.mainloop()
- else:
- r = Tk()
- r.title("D:")
- r.geometry("150x50")
- rlbl = Label(r, text="\n[!] Invalid Login")
- rlbl.pack()
- r.mainloop()
- creds.close()
- ##def AdminCheck():
- ## with open(Admincreds) as f:
- ## data = f.readlines() #puts the entire document into the info.
- ## username = data[0].rstrip()\
- ## #data[0] is the first line and data[1]would be the second line ect
- ## password = data[1].rstrip()\
- ## #using rstrip it remove the new line word before we input it
- ##
- ## if nameLogin.get() == username and passwordLogin.get() == password:
- ## #checking if data is correct
- ## DelUser()
- ## else:
- ## r = Tk()
- ## r.title("D:")
- ## r.geometry("150x50")
- ## rlbl = Label(r, text="\n[!] Invalid Login")
- ## rlbl.pack()
- ## r.mainloop()
- def AdminLogin():
- global AdminNameLogin
- global AdminPasswordLogin
- global rootB
- AdminConfimation = False
- rootB= Tk()
- rootB.title("Admin Confirmation")
- intruction= Label(rootB, text="Please Enter Admin Details\n")
- intruction.grid(stick=E)
- AdminNameLabel= Label(rootA, text="Username: ")
- AdminPasswordLabel= Label(rootA, text="Password: ")
- AdminNameLabel.grid(row=1, sticky=W)
- AdminPasswordLabel.grid(row=2,sticky=W)
- AndminNameLogin= Entry(rootA)
- AdminPasswordLogin = Entry(rootA, show="*")
- AdminNameLogin.grid(row=1, column=1)
- AdminPasswordLogin.grid(row=2, column=1)
- loginButton = Button(rootA, text="Login", command=AdminCheck) #the logic button
- loginButton.grid(columnspan=2, sticky=W)
- def adminpage():
- r = Tk()
- r.title("Admin Page")
- r.geometry("150x50")
- #ListLabel = Label(rootsC, text="Current Users:")
- #ListLabel.grid(row=1, column=0, sticky=W)
- rlbl = Label(r, text="\n[+] Admin Logged In")
- rlbl.pack() #pack is just like .grid but used for other things
- r.mainloop()
- def DelUser():
- os.remove(creds)
- rootA.destory()
- signup()
- ##ADD IN A LISTBOX
- #if os.path.isfile(creds):
- login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement