Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. #Josh Averill 10/09/2018 Nea Task Version one (Login)
  2. import random
  3.  
  4. UsernamePassword = []
  5. UsefulList = []
  6. #Lists used to store data for passwords as well as checking them
  7. with open("UsernamePassword.csv") as DataFile:
  8. for EachLine in DataFile:
  9. EachLine=EachLine.strip()
  10. EachColumnItem = EachLine.split(",")
  11. UsernamePassword.append(EachColumnItem)
  12.  
  13. def MainProgram():
  14. Dice_Roll()
  15.  
  16. def Dice_Roll():
  17. DiceRoll = str(input("Do you want to roll the dice?"))
  18. if DiceRoll == "yes":
  19. print("Your number is: " + str(random.randint(1,6)))
  20. MainProgram()
  21. else:
  22. print("System failure, please contact developer.")
  23.  
  24. def Username():
  25. Firstname = str(input("What is your firstname?"))
  26. Age = str(input("How old are you"))
  27. username = Firstname[:3]+Age
  28. print("Your username is:", username)
  29.  
  30. return username
  31. #Function To create a username for new users
  32. def Password():
  33. password = str(input("What would you like your password to be"))
  34. return password
  35. #Asks new user for password of their choice
  36.  
  37. def NewLogin(UsernamePassword,UsefulList):
  38. username = Username()
  39. password = Password()
  40. UsefulList.append(username)
  41. UsefulList.append(password)
  42. UsernamePassword.append(UsefulList)
  43. with open("UsernamePassword.csv", "w") as DataFile:
  44. for EachList in UsernamePassword:
  45. for EachItem in EachList:
  46. DataFile.write(EachItem + ",")
  47. DataFile.write("\n")
  48. #^^^^^^^ New login function creates and saves a new user profile
  49. def Login(UsernamePassword,UsefulList):
  50. WhewHew = 0
  51. username = str(input("What is your username"))
  52. password = str(input("What is your password"))
  53. for EachList in UsernamePassword:
  54. if username and password in UsernamePassword[WhewHew]:
  55. Row = WhewHew
  56. print("Username and password correct Welcome to the dice game")
  57. Dice_Roll()
  58. else:
  59. WhewHew = WhewHew+1
  60. print("Username Incorrect")
  61. Login(UsernamePassword,UsefulList)
  62. #^^^^^ Login function manages the Login for current users checking a external file to authenticate their login
  63. NewUser = str(input("Are you a new user?"))
  64. NewUser = str.upper(NewUser)
  65. if NewUser == "NO":
  66. Login(UsernamePassword,UsefulList)
  67. elif NewUser == "YES":
  68. NewLogin(UsernamePassword,UsefulList)
  69. print("Time to Login")
  70. Login(UsernamePassword,UsefulList)
  71. else:
  72. print("Please enter yes or no")
  73. Login(UsernamePassword,UsefulList)
  74. #This short section of code is what checks if the user is new or not
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement