Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. from tkinter import *
  2. import os
  3.  
  4. class login:
  5.  
  6. creds = 'H:\PythonGroupWork\Logins\users.txt'# This just sets the variable creds to 'tempfile.temp'
  7.  
  8. def Signup(self): # This is the signup definition,
  9. global pwordE # These globals just make the variables global to the entire script, meaning any definition can use them
  10. global nameE
  11. global roots
  12.  
  13. roots = Tk() # This creates the window, just a blank one.
  14. roots.title('Signup') # This renames the title of said window to 'signup'
  15. intruction = Label(roots, text='Please Enter new Credidentialsn') # This puts a label, so just a piece of text saying 'please enter blah'
  16. intruction.grid(row=0, column=0, sticky=E) # This just puts it in the window, on row 0, col 0. If you want to learn more look up a tkinter tutorial :)
  17.  
  18. nameL = Label(roots, text='New Username: ') # This just does the same as above, instead with the text new username.
  19. pwordL = Label(roots, text='New Password: ') # ^^
  20. nameL.grid(row=1, column=0, sticky=W) # Same thing as the instruction var just on different rows. :) Tkinter is like that.
  21. pwordL.grid(row=2, column=0, sticky=W) # ^^
  22.  
  23. nameE = Entry(roots) # This now puts a text box waiting for input.
  24. pwordE = Entry(roots, show='*') # Same as above, yet 'show="*"' What this does is replace the text with *, like a password box :D
  25. nameE.grid(row=1, column=1) # You know what this does now :D
  26. pwordE.grid(row=2, column=1) # ^^
  27.  
  28. signupButton = Button(roots, text='Signup', command=FSSignup) # This creates the button with the text 'signup', when you click it, the command 'fssignup' will run. which is the def
  29. signupButton.grid(columnspan=2, sticky=W)
  30. roots.mainloop() # This just makes the window keep open, we will destroy it soon
  31.  
  32. def FSSignup(self):
  33. with open(creds, 'w') as f: # Creates a document using the variable we made at the top.
  34. f.write(nameE.get()) # nameE is the variable we were storing the input to. Tkinter makes us use .get() to get the actual string.
  35. f.write('n') # Splits the line so both variables are on different lines.
  36. f.write(pwordE.get()) # Same as nameE just with pword var
  37. f.close() # Closes the file
  38.  
  39. roots.destroy() # This will destroy the signup window. :)
  40. Login() # This will move us onto the login definition :D
  41.  
  42. def Login(self):
  43. global nameEL
  44. global pwordEL # More globals :D
  45. global rootA
  46.  
  47. rootA = Tk() # This now makes a new window.
  48. rootA.title('Login') # This makes the window title 'login'
  49.  
  50. intruction = Label(rootA, text='Please Loginn') # More labels to tell us what they do
  51. intruction.grid(sticky=E) # Blahdy Blah
  52.  
  53. nameL = Label(rootA, text='Username: ') # More labels
  54. pwordL = Label(rootA, text='Password: ') # ^
  55. nameL.grid(row=1, sticky=W)
  56. pwordL.grid(row=2, sticky=W)
  57.  
  58. nameEL = Entry(rootA) # The entry input
  59. pwordEL = Entry(rootA, show='*')
  60. nameEL.grid(row=1, column=1)
  61. pwordEL.grid(row=2, column=1)
  62.  
  63. loginB = Button(rootA, text='Login', command=CheckLogin) # This makes the login button, which will go to the CheckLogin def.
  64. loginB.grid(columnspan=2, sticky=W)
  65.  
  66. rmuser = Button(rootA, text='Delete User', fg='red', command=DelUser) # This makes the deluser button. blah go to the deluser def.
  67. rmuser.grid(columnspan=2, sticky=W)
  68. rootA.mainloop()
  69.  
  70. def CheckLogin(self):
  71. with open(creds) as f:
  72. data = f.readlines() # This takes the entire document we put the info into and puts it into the data variable
  73. uname = data[0].rstrip() # Data[0], 0 is the first line, 1 is the second and so on.
  74. pword = data[1].rstrip() # Using .rstrip() will remove the n (new line) word from before when we input it
  75.  
  76. if nameEL.get() == uname and pwordEL.get() == pword: # Checks to see if you entered the correct data.
  77. r = Tk() # Opens new window
  78. r.title(':D')
  79. r.geometry('150x50') # Makes the window a certain size
  80. rlbl = Label(r, text='n[+] Logged In') # "logged in" label
  81. rlbl.pack() # Pack is like .grid(), just different
  82. r.mainloop()
  83. else:
  84. r = Tk()
  85. r.title('D:')
  86. r.geometry('150x50')
  87. rlbl = Label(r, text='n[!] Invalid Login')
  88. rlbl.pack()
  89. r.mainloop()
  90.  
  91. def DelUser(self):
  92. os.remove(creds) # Removes the file
  93. rootA.destroy() # Destroys the login window
  94. Signup() # And goes back to the start!
  95.  
  96. if os.path.isfile(creds):
  97. Login(self)
  98. else: # This if else statement checks to see if the file exists. If it does it will go to Login, if not it will go to Signup :)
  99. Signup(self)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement