Advertisement
Guest User

Untitled

a guest
Dec 27th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.54 KB | None | 0 0
  1. from tkinter import *
  2. import os
  3.  
  4. creds = 'temp.temp'
  5. credss = {}
  6.  
  7.  
  8. def signUp():
  9.     global windowSignIn
  10.     global entryLogin
  11.     global entryPswd
  12.     windowSignIn = Tk()
  13.     windowSignIn.title('Sign up')
  14.     instruction = Label(windowSignIn, text='Please enter new credidentials\n')
  15.     instruction.grid(row=0, column=0, sticky=E)
  16.  
  17.     labelLogin = Label(windowSignIn, text='New login: ')
  18.     labelLogin.grid(row=1, column=0, sticky=W)
  19.     labelPswd = Label(windowSignIn, text='New password: ')
  20.     labelPswd.grid(row=2, column=0, sticky=W)
  21.  
  22.     entryLogin = Entry(windowSignIn)
  23.     entryLogin.grid(row=1, column=1)
  24.     entryPswd = Entry(windowSignIn, show='*')
  25.     entryPswd.grid(row=1, column=1)
  26.  
  27.     buttonSign = Button(windowSignIn, text='Sign up', command=bSignup)
  28.     buttonSign.grid(columnspan=2, sticky=W)
  29.     windowSignIn.mainloop()
  30.  
  31.  
  32. def bSignup():
  33.     with open(creds, 'w') as f:
  34.         f.write(entryLogin.get())
  35.         f.write(':')
  36.         f.write(entryPswd.get())
  37.         f.write('\n')
  38.         f.close()
  39.  
  40.     windowSignIn.destroy()
  41.     logIn()
  42.  
  43.  
  44. def logIn():
  45.     global entryLoginL
  46.     global entryPswdL
  47.     global windowLogin
  48.  
  49.     windowLogin = Tk()
  50.     windowLogin.title('Login')
  51.  
  52.     instruction = Label(windowLogin, text='Log in!\n')
  53.     instruction.grid(sticky=E)
  54.     labelLoginL = Label(windowLogin, text='Login: ')
  55.     labelLoginL.grid(row=1, sticky=W)
  56.     labelPswdL = Label(windowLogin, text='Password: ')
  57.     labelPswdL.grid(row=2, sticky=W)
  58.  
  59.     entryLoginL = Entry(windowLogin)
  60.     entryLoginL.grid(row=1, column=1)
  61.     entryPswdL = Entry(windowLogin, show='*')
  62.     entryPswdL.grid(row=2, column=1)
  63.  
  64.     buttonLog = Button(windowLogin, text='Login', command=checkLogin)
  65.     buttonLog.grid(columnspan=2, sticky=W)
  66.  
  67.     logOutB = Button(windowLogin, text="Logout", command=logOut)
  68.     logOutB.grid(columnspan=2, sticky=E)
  69.     windowLogin.mainloop()
  70.  
  71.  
  72. def checkLogin():
  73.     with open(creds, 'r') as f:
  74.         for line in f:
  75.             user, pswd = line.strip().split(':')
  76.             credss[user] = pswd
  77.  
  78.     username = entryLoginL.get()
  79.     password = entryPswdL.get()
  80.     r = Tk()
  81.     r.title('Check')
  82.     r.geometry('150x50')
  83.     message = Label(r)
  84.     if username in credss and credss[username] == password:
  85.         message.configure(text="Logged in.")
  86.         message.pack()
  87.         r.mainloop()
  88.     else:
  89.         message.configure(text="Username and password don't match")
  90.         message.pack()
  91.         r.mainloop()
  92.  
  93.  
  94. def logOut():
  95.     windowLogin.destroy()
  96.     signUp()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement