Advertisement
ItIsShadow

Python Login

Jan 24th, 2020
3,660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.29 KB | None | 0 0
  1.     def enterDetails(users, passwords):
  2.         #Another definition
  3.         global enterUser
  4.         #Another global variable
  5.         userAlready = messagebox.askyesno("Account?","Do you already have an account?")
  6.         #Creates a message box asking if they have got an account, returning a boolean
  7.         if userAlready == True:
  8.             #If the user presses 'Yes'...
  9.             enterUser = input("Enter your username\n> ").lower()
  10.             #Gets the username and puts it in lower case
  11.             if enterUser in users:
  12.                 #if the user is in the users.txt document...
  13.                 enterPass = str(input("Enter your password\n> "))
  14.                 #Gets the password
  15.                 userPos = users.index(enterUser)
  16.                 #Creates a variable and stores the number of lines in users
  17.                 if enterPass in passwords:
  18.                     #if the passwrod entered is in pass.txt...
  19.                     passPos = passwords.index(enterPass)
  20.                     #indexes the passwords  
  21.                     if userPos == passPos:
  22.                         #if the 2 numbers are the same
  23.                         print ("You have successfully logged in", enterUser)
  24.                         time.sleep(5)
  25.                         clear()
  26.                         #log them in
  27.                         return True
  28.                     #moves on to the next definition
  29.                     else:
  30.                         #else...
  31.                         print("You have entered the wrong password, please try again!")
  32.                         #if the password was wrong, ask them to re enter the user and password and restarts program
  33.                         time.sleep(5)
  34.                         clear()
  35.                 else:
  36.                     #else...
  37.                     print("We couldn't find your password, please try again!")
  38.                     #if the password isn't in pass.txt, ask them to re enter user and password and resets program
  39.                     time.sleep(5)
  40.                     clear()
  41.             else:
  42.                 #else...
  43.                 retryUser = messagebox.askyesno("Retry?","We couldn't find your username, would you like to retry?")
  44.                 #asks them if they want to try another username
  45.                 if retryUser == True:
  46.                     #if they do...
  47.                     i = 0
  48.                     #returns i as 0, restarting the loop
  49.                     time.sleep(5)
  50.                     clear()
  51.                 else:
  52.                     #else...
  53.                     quit()
  54.                     #it quits the program
  55.             return False
  56.         #returns false (I believe this is obselete)
  57.         else:
  58.             #else if they don't have a user
  59.             file = open('users.txt','a')
  60.             #open users.txt as 'amend'
  61.             newUser = input("Please enter username\n").lower()
  62.             #asks for a new username and puts it in lower case
  63.             file.write("\n" + newUser)
  64.             #writes the new user on a new line
  65.             file.close()
  66.             #closes the file
  67.  
  68.             f = 0
  69.             #defines f as 0
  70.             while f == 0:
  71.                 #creates a loop
  72.                 file = open('pass.txt','a')
  73.                 #opens pass.txt as 'amend'
  74.                 newPass = input("Please enter password\n")
  75.                 #asks for a new password
  76.                 confirmPass = input("Please confirm password\n")
  77.                 #asks for comformation
  78.                 if newPass == confirmPass:
  79.                     #if they are the same...
  80.                     file.write("\n" + newPass)
  81.                     #write the password to the file
  82.                     file.close()
  83.                     #close the file
  84.                     print("New user created! Please restart the program and log in with your credidentials")
  85.                     #prints text
  86.                     quit()
  87.                     #quits the program
  88.                 else:
  89.                     #else...
  90.                     print("Passwords didn't match, please try again or use a different password.")
  91.                     #tells them the passwords don't match and restarts the password loop
  92.                     f == 0
  93.                     time.sleep(5)
  94.                     clear()
  95.                     #sets f to 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement