Advertisement
Guest User

Untitled

a guest
Apr 13th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. import re
  2. import datetime
  3. import sys
  4.  
  5. def mainMenu():
  6. print("Welcome - Please select from the following selections below:\n Press 1 to Login\n Press 2 to Create an Account")
  7. selection = int(input(""))
  8.  
  9. if selection == 1:
  10. login()# Since the user already has an account, this will take them to login.
  11. else:
  12. registerAccount() #This will take the user to register
  13.  
  14. def menu():
  15. print("\nWelcome",login_info[0],"to the main menu - select from the options below:\n\nPress 1 to change password \n\nPress 2 to view user details \n\nPress 3 to list all users \n\nPress 4 to check your password strength")
  16. selection = int(input(""))
  17.  
  18. if selection == 1:
  19. changePassword()
  20. if selection == 2:
  21. userInformation()
  22.  
  23.  
  24. def registerAccount():
  25. global password, username
  26.  
  27. username = input("Please input your desired username")
  28. while True:
  29. password = input("Please input your desired password")
  30. if len(password) < 6: #This loop to make sure the user inputs a valid password.
  31. print("\nYou must enter a password with a minimum of 6 characters\n")
  32. elif len(password) > 12:
  33. print("\nPassword is too long!")
  34. else:
  35. break
  36. registerUserInformation()
  37.  
  38. def registerUserInformation():
  39. global fullName, emailAddress, dateofBirth
  40. fullName = input("Please enter your full name")
  41. print("\nPlease enter a valid email address")
  42. while True:
  43. emailAddress = input("")
  44. addressToVerify = emailAddress.lower() #Turns the email to all lower case before verifying address
  45. match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', addressToVerify)
  46.  
  47. if match == None:
  48. print("ERROR! The e-mail you have entered is NOT valid, please try again:")
  49. else:
  50. break
  51. print("\nPlease enter your date of birthday (DD/MM/YYYY) *Include the /'s!:")
  52.  
  53. while True:
  54. dateofBirth = input("Enter the date in format 'dd/mm/yy' : ")
  55. day,month,year = dateofBirth.split('/')
  56. isValidDate = True
  57. try:
  58. datetime.datetime(int(year),int(month),int(day))
  59. except ValueError :
  60. isValidDate = False
  61. if(isValidDate) :
  62. print ("Account created! Logging in...")
  63. break
  64. else :
  65. print ("Please enter the date in the correct formart:")
  66. storingInformation()
  67.  
  68. def storingInformation(): #!IMPORTANT! This is done after the account/user information so that if the program closes that information will NOT be stored!!
  69. file = open("Accounts.txt","a") #This ensures that all information will be collected and then stored in this function.
  70. file.write(username)
  71. file.write(" ")
  72. file.write(password)
  73. file.write("\n")
  74. file.close()
  75.  
  76. file = open("UserInformation.txt","a")
  77. file.write(fullName)
  78. file.write(" ")
  79. file.write(emailAddress)
  80. file.write(" ")
  81. file.write(dateofBirth)
  82. file.write("\n")
  83. file.close()
  84. print("\nAccount Created! You are now able to log in\n")
  85. mainMenu()
  86.  
  87. def login():
  88. count = 0
  89. while True:
  90. global login_info, userloc
  91. username = input("Please enter your username")
  92. password = input("Please enter your password")
  93. userloc = -1
  94. count += 1
  95. if count == 3:
  96. print("You have exceeded the maximum amount of login attempts. Exiting...")
  97. break
  98. with open('Accounts.txt') as inputFile:
  99. login_info = [ line.strip().split() for line in inputFile]
  100. print(login_info)
  101. for pos, line in enumerate(login_info): # Read the lines
  102. #login_data = line.strip().split() # Split on the space, and store the results in a list of two strings
  103. if username == line[0] and password == line[1]:
  104. print("\nCorrect credentials! You are now logging in...")
  105. userloc = pos
  106. menu()
  107. return True
  108. else:
  109. print("Incorrect credentials.")
  110.  
  111. def changePassword():
  112. print("Are you sure you want to change your password?\nPress 1 for Yes \nPress 2 for No")
  113. selection = int(input())
  114. if selection == 1:
  115. print("Please enter your new password")
  116. newPass = input("")
  117. login_info[userloc][1] = newPass
  118. with open("Accounts.txt", 'w') as of:
  119. for pair in login_info:
  120. of.write(pair[0] + " " + pair[1] + "\n")
  121. else:
  122. menu()
  123.  
  124. def userInformation():
  125. print(login_info[0], ",here is your registered information:\n")
  126. for line in open("UserInformation.txt","r").readlines():
  127. user_info = line.split()
  128. print("Your name is:",user_info[0])
  129. print("Your e-mail is:",user_info[1])
  130. print("Your date of birth is:",user_info[2])
  131. print("\n Press 1 to return to the main menu")
  132. selection = int(input())
  133. if selection == True:
  134. menu()
  135.  
  136. def passCheck():
  137. pass
  138. mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement