Guest User

Untitled

a guest
Nov 13th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.31 KB | None | 0 0
  1. #coding: utf-8
  2. from tkinter import *
  3. from tkinter import messagebox
  4. import pickle
  5. import os
  6. root = Tk()
  7. root.geometry("300x250")
  8. root.title("Вход/регистрация")
  9. def log(): #Регистрация
  10. global e2
  11. global e3
  12. global b2
  13. global e
  14. global reg
  15. t = Label(root, text = "Зарегистрируйтесь для входа", font="Arial 16")
  16. t.grid(row =0, column=0, columnspan=3)
  17. t1 = Label(root, text = "*Логин:", font="Arial 10")
  18. t1.grid(row=2, column=0, sticky="w")
  19. e = Entry(root)
  20. e.focus_set()
  21. e.grid(row=2, column=1, sticky="w")
  22. t2 = Label(root, text = "*Пароль:", font="Arial 10")
  23. t2.grid(row=3, column=0, sticky="w")
  24. e2 = Entry(show="*")
  25. e2.grid(row=3, column=1, sticky="w")
  26. t3 = Label(root, text = "*Повторите пароль:", font="Arial 10")
  27. t3.grid(row=4, column=0, sticky="w")
  28. e3 = Entry(show="*")
  29. e3.grid(row=4, column=1, sticky="w")
  30. reg = Button(root, text="Зарегистрироваться", overrelief="sunken", command = lambda: check())
  31. reg.grid(row=5, column=0)
  32. b2 = Button(root, text="Показать пароль", command = lambda: offe(), overrelief="sunken")
  33. b2.grid(row=5, column=1, sticky="w")
  34. def offe(): #Показать пароль
  35. e2.config(show="")
  36. e3.config(show="")
  37. b2.config(command = lambda: offe2(), text="Показать пароль")
  38. def offe2(): #Скрыть пароль
  39. e2.config(show="*")
  40. e3.config(show="*")
  41. b2.config(command = lambda: offe(), text = "Скрыть пароль")
  42. def check(): #Проверка логина и пароля
  43. easypas=['qwerty1234','qwerty1234', 'qwerty12345', '123456', '1234567', '12345678', '123456789', '1234567890', '0123456789', 'qwerty12', 'qwerty123']
  44. easypas=str(easypas)
  45. if(e.get() == "" or e3.get() == "" or e2.get() == ""):
  46. messagebox.showwarning("Ошибка", "Вы должны заполнить все пустые поля.")
  47. if e.get() == "" and e2.get() == "" and e3.get() == "":
  48. e.config(bg="orange")
  49. e2.config(bg="orange")
  50. e3.config(bg="orange")
  51. elif e.get() == "" and e2.get() == "":
  52. e.config(bg="orange")
  53. e2.config(bg="orange")
  54. e3.config(bg="white")
  55. elif e.get() == "" and e3.get() == "":
  56. e.config(bg="orange")
  57. e3.config(bg="orange")
  58. e2.config(bg="white")
  59. elif e.get() == "":
  60. e.config(bg="orange")
  61. e2.config(bg="white")
  62. e3.config(bg="white")
  63. elif e2.get() == "" and e3.get() == "":
  64. e2.config(bg="orange")
  65. e3.config(bg="orange")
  66. e.config(bg="white")
  67. elif e2.get() == "" and e.get() == "":
  68. e2.config(bg="orange")
  69. e.config(bg="orange")
  70. e3.config(bg="white")
  71. elif e2.get() == "":
  72. e2.config(bg="orange")
  73. e.config(bg="white")
  74. e3.config(bg="white")
  75. elif e3.get() == "" and e.get() == "":
  76. e3.config(bg="orange")
  77. e.config(bg="orange")
  78. e2.config(bg="white")
  79. elif e3.get() == "" and e2.get() == "":
  80. e2.config(bg="orange")
  81. e3.config(bg="orange")
  82. e.config(bg="")
  83. elif e3.get() == "":
  84. e3.config(bg="orange")
  85. e2.config(bg="white")
  86. e.config(bg="white")
  87. elif(len(e.get()) < 4):
  88. e.config(bg="orange")
  89. messagebox.showwarning("Внимание", "Логин должен состоять минимум\n из 4 символов.")
  90. elif(len(e2.get()) < 6 and len(e3.get()) < 6):
  91. e.config(bg="#32CD32")
  92. e2.config(bg="orange")
  93. e3.config(bg="orange")
  94. messagebox.showwarning("Внимание", "Пароль должен состоять минимум\n из 6 символов.")
  95. elif(e2.get() in easypas and e3.get() in easypas):
  96. messagebox.showwarning("Внимание", "Слишком лёгкий пароль.")
  97. e.config(bg="#32CD32")
  98. e2.config(bg="orange")
  99. e3.config(bg="orange")
  100. else:
  101.  
  102. if e3.get() == e2.get():
  103. reg.config(state=DISABLED)
  104. b2.config(state=DISABLED)
  105. e.config(state=DISABLED, disabledbackground="#32CD32", disabledforeground="black")
  106. e3.config(state=DISABLED, disabledbackground="#32CD32", disabledforeground="black", show="*")
  107. e2.config(state=DISABLED, disabledbackground="#32CD32", disabledforeground="black", show="*")
  108. messagebox.showinfo("Информация", "Запомните ваш логин и пароль!\nЛогин: " + e.get() + "\nПароль: " + e3.get())
  109. global save
  110. save()
  111.  
  112. else:
  113. e3.config(state=NORMAL)
  114. e.config(bg="white")
  115. e2.config(state=NORMAL)
  116. e3.config(background="red")
  117. e2.config(background="red")
  118. messagebox.showerror("Ошибка", "Пароли не совпадают!")
  119.  
  120. def save(): #Проверка на наличие файла
  121. if os.path.exists("logins.txt"):
  122. save2()
  123. else:
  124. messagebox.showinfo("Информация", "Не найден файл logins.txt\nСоздание..")
  125. file = open("logins.txt", "wb")
  126. file.close()
  127. save2()
  128. def save2(): #Запись логина и пароля
  129. sev_pass = e3.get()
  130. sev_login = e.get()
  131.  
  132. file = open('logins.txt', "ab")
  133. pickle.dump(sev_pass, file)
  134. pickle.dump(sev_login, file)
  135. file.close()
  136. password()
  137. def password (): #Вход
  138. global sev_pass
  139. global sev_login
  140. file = open("logins.txt", "rb")
  141. sev_pass = pickle.load(file)
  142. sev_login = pickle.load(file)
  143. file.close()
  144. t1 = Label(root, text = "Вход в систему", font="Arial 16")
  145. t1.grid(row=6,column=0, columnspan=3)
  146. global reg1
  147. global b2
  148. global e1
  149. global e21
  150. global b21
  151. t11 = Label(root, text = "Логин:", font="Arial 10")
  152. t11.grid(row=7,column=0, sticky="w")
  153. e1 = Entry()
  154. e1.grid(row=7,column=1, sticky="w")
  155. e1.focus_set()
  156. t21 = Label(root, text = "Пароль:", font="Arial 10")
  157. t21.grid(row=8, column=0, sticky="w")
  158. e21 = Entry(show="*")
  159. e21.grid(row=8, column=1, sticky="w")
  160. reg1 = Button(root, text="Авторизация", overrelief="sunken", command = lambda: check2())
  161. reg1.grid(row=9, column=0)
  162. b21 = Button(root, text="Показать пароль", command = lambda: offe1(), overrelief="sunken")
  163. b21.grid(row=9, column=1, sticky="w")
  164. def offe1(): #Показать/скрыть пароль
  165. e21.config(show="")
  166. b21.config(command = lambda: offe21(), text="Показать пароль")
  167. def offe21():
  168. e21.config(show="*")
  169. b21.config(command = lambda: offe1(), text = "Скрыть пароль")
  170. def check2():#Проверить лооин и пароль
  171. if e1.get()== "" or e21.get() == "":
  172. messagebox.showwarning("Ошибка", "Вы должны заполнить все пустые поля.")
  173. if e1.get()=="" and e21.get()== "":
  174. e1.config(bg="orange")
  175. e21.config(bg="orange")
  176. elif e1.get()=="":
  177. e1.config(bg="orange")
  178. e21.config(bg="white")
  179. elif e21.get()=="":
  180. e21.config(bg="orange")
  181. e1.config(bg="white")
  182. else:
  183. if sev_pass == e21.get() and sev_login == e1.get():
  184. success = Label(text = "Вы успешно вошли в аккаунт", fg ="green")
  185. success.grid(row=10, columnspan=3)
  186. messagebox.showinfo("Успешно", "Вы вошли в аккаунт.")
  187. e1.config(state=DISABLED, disabledbackground="#32CD32", disabledforeground="black")
  188. e21.config(state=DISABLED, disabledbackground="#32CD32", disabledforeground="black")
  189. reg1.config(state=DISABLED)
  190. b21.config(state=DISABLED)
  191. elif sev_pass != e21.get():
  192. messagebox.showerror("Ошибка", "Неверный пароль!")
  193. e1.config(background="red")
  194. e21.config(background="red")
  195. elif sev_login != e1.get():
  196. messagebox.showerror("Ошибка", "Неверный логин!")
  197. e1.config(background="red")
  198. log()
  199. root.mainloop()
Add Comment
Please, Sign In to add comment