Advertisement
Guest User

Both Your Sisters are fit

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