Advertisement
Guest User

Mathew Is Incest (Called His Sister Fit)

a guest
Dec 7th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. import random
  2. #2D Array to store the users and passwords when the program is running
  3. usersArray = []
  4. songsAndArtistsArray = []
  5.  
  6. def loadFile():
  7. usersFile = open("users.txt", "r")
  8.  
  9. for line in usersFile:
  10. user = []
  11. user = line.split(",")
  12.  
  13. user[len(user)-1] = user[len(user)-1].strip("\n")
  14.  
  15. usersArray.append(user)
  16.  
  17. usersFile.close()
  18.  
  19. songsFile = open("users.txt", "r")
  20.  
  21. for line in songsFile:
  22. song = []
  23. song = line.split(",")
  24.  
  25. song[len(user)-1] = song[len(user)-1].strip("\n")
  26.  
  27. songsAndArtistsArray.append(user)
  28.  
  29. songsFile.close()
  30. print(songsAndArtistsArray)
  31.  
  32. def signUp():
  33. #Ask the user for their name
  34. firstName = input("Please enter your first name\n")
  35. surname = input("Please enter your surname\n")
  36.  
  37. #Generate the first part of the username
  38. username = firstName + surname
  39.  
  40. #Concatenate 3 random numbers at the end
  41. counter = 0
  42. while counter < 3:
  43. randomNumber = random.randint(0,9)
  44. username = username + str(randomNumber)
  45. counter = counter + 1
  46.  
  47. #Ask for the password two times
  48. password = input("Please enter your password\n")
  49. password1 = input("Please re-enter your password\n")
  50.  
  51. #Continue the program if the passwords match
  52. if password == password1:
  53. print("Passwords match")
  54. else:
  55. print("Passwords don't match")
  56. exit()
  57.  
  58. print("Your username is " + username + " please make a note of this")
  59.  
  60. user = []
  61. user.append(username)
  62. user.append(password)
  63. usersArray.append(user)
  64. print(usersArray)
  65.  
  66. usersFile = open("users.txt", "w")
  67.  
  68. for user in usersArray:
  69. lineForFile = ""
  70.  
  71. for item in user:
  72. if item == user[len(user)-1]:
  73. lineForFile = lineForFile + item + "\n"
  74. else:
  75. lineForFile = lineForFile + item + ","
  76.  
  77. print(lineForFile)
  78. usersFile.write(lineForFile)
  79.  
  80. usersFile.close()
  81.  
  82. def login():
  83.  
  84. Loggedin = False
  85.  
  86. while not Loggedin:
  87.  
  88. enteredUsername = input("Enter your username\n")
  89. enteredPassword = input("Enter your password\n")
  90.  
  91. for user in usersArray:
  92. if enteredUsername == user[0] and enteredPassword == user[1]:
  93. print("login successful")
  94. Loggedin = True
  95.  
  96. if not Loggedin:
  97. print("username and password incorrect")
  98.  
  99.  
  100.  
  101.  
  102. '''Main Program'''
  103.  
  104. loadFile()
  105.  
  106. running = True
  107.  
  108. while running:
  109.  
  110. menuChoice = input("Menu: \n1. Sign up\n2. Login\n")
  111.  
  112. if menuChoice == "1":
  113. signUp()
  114. elif menuChoice == "2":
  115. if login() == True:
  116. pass
  117. else:
  118. exit()
  119.  
  120. answer = input("Do you want to run the program again? y/n\n")
  121.  
  122. if answer == "y":
  123. running = True
  124. elif answer == "n":
  125. running = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement