Advertisement
Guest User

Untitled

a guest
Jan 10th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.46 KB | None | 0 0
  1. from tkinter import *
  2. import os
  3.  
  4. global AdminConfirmation
  5. AdminConfirmation = False
  6. def signup():
  7.     global passwordEntry
  8.     global nameEntry
  9.     global roots
  10.  
  11.     roots = Tk()
  12.     roots.title("Signup")
  13.     prompts = Label(roots, text="Please enter your account details.\n")
  14.     prompts.grid(row=0, column=0, sticky=E)
  15.  
  16.     nameLabel = Label(roots, text="New Username: ")
  17.     passwordLabel = Label(roots, text="New Password: ")
  18.     nameLabel.grid(row=1, column=0, sticky=W)
  19.     passwordLabel.grid(row=2, column=0, sticky=W)
  20.  
  21.     nameEntry = Entry(roots)
  22.     passwordEntry= Entry(roots, show="*")
  23.     nameEntry.grid(row=1, column=1)
  24.     passwordEntry.grid(row=2, column=1)
  25.  
  26.     signupButton = Button(roots, text="Signup", command = FSSignup)
  27.     signupButton.grid(columnspan=2, sticky=W)
  28.     roots.mainloop()
  29. def AdminSignup():
  30.     global AdminPasswordEntry
  31.     global AdminNameEntry
  32.     global rootsC
  33.  
  34.     rootsC = Tk()
  35.     rootsC.title("Admin Signup")
  36.     prompts = Label(rootsC, text="Please enter your admin details.\n")
  37.     prompts.grid(row=0, column=0, sticky=E)
  38.  
  39.     AdminNameLabel = Label(rootsC, text="Username: ")
  40.     AdminPasswordLabel = Label(rootsC, text="Password: ")
  41.     AdminNameLabel.grid(row=1, column=0, sticky=W)
  42.     AdminPasswordLabel.grid(row=2, column=0, sticky=W)
  43.  
  44.     AdminNameEntry = Entry(rootsC)
  45.     AdminPasswordEntry= Entry(rootsC, show="*")
  46.     AdminNameEntry.grid(row=1, column=1)
  47.     AdminPasswordEntry.grid(row=2, column=1)
  48.  
  49.     signupButton = Button(rootsC, text="Signup", command = AdminFSignup)
  50.     signupButton.grid(columnspan=2, sticky=W)
  51.     rootsC.mainloop()
  52.  
  53. def FSSignup():
  54.     creds = open("loginfile.txt","a") #this is where the student details will be stored
  55.     print(str(nameEntry.get()),passwordEntry.get(),file=creds, sep=",")
  56.     creds.close()
  57.  
  58.     roots.destroy() #this removes the signup window
  59. def AdminFSignup():
  60.     Admincreds = open("Adminlogin.txt","a") #this is where the admin details will be stored
  61.     print(AdminNameEntry.get(),AdminPasswordEntry.get(),file=Admincreds, sep=",")
  62.     Admincreds.close()
  63.     rootsC.destroy() #this removes the signup window
  64. def login():
  65.     global nameLogin
  66.     global passwordLogin
  67.     global rootA
  68.  
  69.     rootA= Tk()
  70.     rootA.title("Login")
  71.  
  72.     intruction= Label(rootA, text="Please Login\n")
  73.     intruction.grid(stick=E)
  74.  
  75.     nameLabel= Label(rootA, text="Username: ")
  76.     passwordLabel= Label(rootA, text="Password: ")
  77.     nameLabel.grid(row=1, sticky=W)
  78.     passwordLabel.grid(row=2,sticky=W)
  79.  
  80.     nameLogin= Entry(rootA)
  81.     passwordLogin = Entry(rootA, show="*")
  82.     nameLogin.grid(row=1, column=1)
  83.     passwordLogin.grid(row=2, column=1)
  84.  
  85.     loginButton = Button(rootA, text="Login", command=CheckLogin) #the logic button
  86.     loginButton.grid(columnspan=2, sticky=W)
  87.    
  88.     AdminSignUp = Button(rootA, text="Admin Signup", fg="black", command=AdminSignup) \
  89.                     #the button to remove users
  90.     AdminSignUp.grid(row=4, sticky=W)
  91.  
  92.     StudentSignUp= Button(rootA, text="Student Signup", command=signup)
  93.     StudentSignUp.grid(row = 4, column = 1)
  94.     #StudentSignUp.grid(columnspan=1,column1)
  95.  
  96.    
  97.     #removeUser = Button(rootA, text="Delete User", fg="red", command=AdminCheck) \
  98.                   #the button to remove users
  99.     #removeUser.grid(columnspan=4, column = 1)
  100.     rootA.mainloop()
  101. def CheckLogin():
  102.     #string = nameLogin.get()
  103.     if str(nameLogin.get())[0] == "a":
  104.         Count=0
  105.         Found= False
  106.         Admincreds = open("Adminlogin.txt","r") #this is where the admin details will be stored
  107.         for admins in Admincreds:
  108.             adminFields = admins.split(",")
  109.             r = Tk()
  110.             r.title("D:")
  111.             r.geometry("150x50")
  112.             #rlbl = Label(r, text=((adminFields[1]))
  113.             #rlbl = Label(r, text=((adminFields[0]),(nameLogin.get()),(adminFields[1]),\
  114.                                   #(passwordLogin.get())))
  115.             rlbl = Label(r, text=((adminFields[0]),(adminFields[1])))
  116.             rlbl.pack()
  117.             r.mainloop()
  118.            
  119.             if nameLogin.get() == adminFields[0]:
  120.                 if passwordLogin.get() == adminFields[1]:
  121.                     count+=1
  122.                     AdminConfirmation = True
  123.                     adminpage()
  124.                     rlbl.pack() #pack is just like .grid but used for other things
  125.                     r.mainloop()
  126.         else:
  127.             r = Tk()
  128.             r.title("D:")
  129.             r.geometry("150x50")
  130.             rlbl = Label(r, text="\n[!] Invalid Login")
  131.             rlbl.pack()
  132.             r.mainloop()
  133.         Admincreds.close()
  134.     else:
  135.         Count=0
  136.         Found=False
  137.         creds = open("loginfile.txt","r") #this is where the student details will be stored
  138.         for students in creds:
  139.             studentFields = students.split(",")
  140.         if nameLogin.get() == studentFields[0]:
  141.             if passwordLogin.get() == studentFields[1]:
  142.                    #checking if data is correct
  143.                 count+=1
  144.                 r = Tk()
  145.                 r.title(":D")
  146.                 r.geometry("150x50")
  147.                 rlbl = Label(r, text="\n[+] Logged In")
  148.                 rlbl.pack() #pack is just like .grid but used for other things
  149.                 r.mainloop()
  150.         else:
  151.             r = Tk()
  152.             r.title("D:")
  153.             r.geometry("150x50")
  154.             rlbl = Label(r, text="\n[!] Invalid Login")
  155.             rlbl.pack()
  156.             r.mainloop()
  157.         creds.close()
  158. ##def AdminCheck():
  159. ##    with open(Admincreds) as f:
  160. ##        data = f.readlines() #puts the entire document into the info.
  161. ##        username = data[0].rstrip()\
  162. ##                   #data[0] is the first line and data[1]would be the second line ect
  163. ##        password = data[1].rstrip()\
  164. ##                   #using rstrip it remove the new line word before we input it
  165. ##    
  166. ##        if nameLogin.get() == username and passwordLogin.get() == password:
  167. ##                   #checking if data is correct
  168. ##            DelUser()
  169. ##        else:
  170. ##            r = Tk()
  171. ##            r.title("D:")
  172. ##            r.geometry("150x50")
  173. ##            rlbl = Label(r, text="\n[!] Invalid Login")
  174. ##            rlbl.pack()
  175. ##            r.mainloop()
  176. def AdminLogin():
  177.     global AdminNameLogin
  178.     global AdminPasswordLogin
  179.     global rootB
  180.     AdminConfimation = False
  181.     rootB= Tk()
  182.     rootB.title("Admin Confirmation")
  183.  
  184.     intruction= Label(rootB, text="Please Enter Admin Details\n")
  185.     intruction.grid(stick=E)
  186.  
  187.     AdminNameLabel= Label(rootA, text="Username: ")
  188.     AdminPasswordLabel= Label(rootA, text="Password: ")
  189.     AdminNameLabel.grid(row=1, sticky=W)
  190.     AdminPasswordLabel.grid(row=2,sticky=W)
  191.  
  192.     AndminNameLogin= Entry(rootA)
  193.     AdminPasswordLogin = Entry(rootA, show="*")
  194.     AdminNameLogin.grid(row=1, column=1)
  195.     AdminPasswordLogin.grid(row=2, column=1)
  196.  
  197.     loginButton = Button(rootA, text="Login", command=AdminCheck) #the logic button
  198.     loginButton.grid(columnspan=2, sticky=W)
  199. def adminpage():
  200.     r = Tk()
  201.     r.title("Admin Page")
  202.     r.geometry("150x50")
  203.     #ListLabel = Label(rootsC, text="Current Users:")
  204.     #ListLabel.grid(row=1, column=0, sticky=W)
  205.     rlbl = Label(r, text="\n[+] Admin Logged In")
  206.     rlbl.pack() #pack is just like .grid but used for other things
  207.     r.mainloop()
  208.    
  209.  
  210.    
  211. def DelUser():
  212.     os.remove(creds)
  213.     rootA.destory()
  214.     signup()
  215.     ##ADD IN A LISTBOX
  216.  
  217. #if os.path.isfile(creds):
  218. login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement