Advertisement
Guest User

Untitled

a guest
Nov 10th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. import csv #import file reader
  2. import time #import time
  3. import random #import random
  4. import operator #import operators
  5. import sys #import system specific parameters
  6.  
  7. def Registration(): #used later on in choice 1
  8. userfile = open("userfile.csv", "a") #use the userfile.csv
  9. username = input("Enter your username ") #username input
  10. password = input("Enter your password ") #password input
  11. WriteLine = username + " " + password + " " #writes lines within userfile.csv from username and password
  12. userfile.write(WriteLine) #write the line
  13. userfile.close() #close the userfile
  14. print ("\nAccount created") #print that the account is created
  15. Menu() #open the menu
  16.  
  17. def Menu(): #the menu itself defined
  18. print (30 * '-') #UI
  19. print (" M A I N - M E N U") #UI
  20. print (30 * '-') #UI
  21. print ("1. Register") #UI
  22. print ("2. Play")#UI
  23. print (30 * '-') #UI
  24. choice = input('Enter your choice [1-2] : ') #defines choice between 1 and 2
  25. choice = int(choice) #string
  26. if choice == 1: #if the choice is 1 (register)
  27. print ("Register Selected") #print register is selected
  28. Registration() #run registration
  29. if choice == 2: #if the choice is 2 (play)
  30. print ("Play Selected") #print play select
  31. LogIn() #next code to run
  32.  
  33. def LogIn():
  34. loginUsername = input("Enter your login username ") #username input
  35. loginPassword = input("Enter your login password ") #password input
  36. loggedIn = False
  37. with open('userfile.csv', 'rb') as csvfile:
  38. userfile = csv.reader(csvfile, delimiter=',')
  39. for row in userfile:
  40. if loginUsername in row:
  41. if loginPassword in row[2]:
  42. loggedIn = True
  43. else:
  44. print("Invalid Password")
  45. else:
  46. print("Invalid Username")
  47. print ("Logged In")
  48.  
  49.  
  50. ############################### call from here ################################
  51.  
  52. Menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement