Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import datetime
- import sys
- def mainMenu():
- print("Welcome - Please select from the following selections below:\n Press 1 to Login\n Press 2 to Create an Account")
- selection = int(input(""))
- if selection == 1:
- login()# Since the user already has an account, this will take them to login.
- else:
- registerAccount() #This will take the user to register
- def menu():
- 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")
- selection = int(input(""))
- if selection == 1:
- changePassword()
- if selection == 2:
- userInformation()
- def registerAccount():
- global password, username
- username = input("Please input your desired username")
- while True:
- password = input("Please input your desired password")
- if len(password) < 6: #This loop to make sure the user inputs a valid password.
- print("\nYou must enter a password with a minimum of 6 characters\n")
- elif len(password) > 12:
- print("\nPassword is too long!")
- else:
- break
- registerUserInformation()
- def registerUserInformation():
- global fullName, emailAddress, dateofBirth
- fullName = input("Please enter your full name")
- print("\nPlease enter a valid email address")
- while True:
- emailAddress = input("")
- addressToVerify = emailAddress.lower() #Turns the email to all lower case before verifying address
- match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', addressToVerify)
- if match == None:
- print("ERROR! The e-mail you have entered is NOT valid, please try again:")
- else:
- break
- print("\nPlease enter your date of birthday (DD/MM/YYYY) *Include the /'s!:")
- while True:
- dateofBirth = input("Enter the date in format 'dd/mm/yy' : ")
- day,month,year = dateofBirth.split('/')
- isValidDate = True
- try:
- datetime.datetime(int(year),int(month),int(day))
- except ValueError :
- isValidDate = False
- if(isValidDate) :
- print ("Account created! Logging in...")
- break
- else :
- print ("Please enter the date in the correct formart:")
- storingInformation()
- def storingInformation(): #!IMPORTANT! This is done after the account/user information so that if the program closes that information will NOT be stored!!
- file = open("Accounts.txt","a") #This ensures that all information will be collected and then stored in this function.
- file.write(username)
- file.write(" ")
- file.write(password)
- file.write("\n")
- file.close()
- file = open("UserInformation.txt","a")
- file.write(fullName)
- file.write(" ")
- file.write(emailAddress)
- file.write(" ")
- file.write(dateofBirth)
- file.write("\n")
- file.close()
- print("\nAccount Created! You are now able to log in\n")
- mainMenu()
- def login():
- count = 0
- while True:
- global login_info, userloc
- username = input("Please enter your username")
- password = input("Please enter your password")
- userloc = -1
- count += 1
- if count == 3:
- print("You have exceeded the maximum amount of login attempts. Exiting...")
- break
- with open('Accounts.txt') as inputFile:
- login_info = [ line.strip().split() for line in inputFile]
- print(login_info)
- for pos, line in enumerate(login_info): # Read the lines
- #login_data = line.strip().split() # Split on the space, and store the results in a list of two strings
- if username == line[0] and password == line[1]:
- print("\nCorrect credentials! You are now logging in...")
- userloc = pos
- menu()
- return True
- else:
- print("Incorrect credentials.")
- def changePassword():
- print("Are you sure you want to change your password?\nPress 1 for Yes \nPress 2 for No")
- selection = int(input())
- if selection == 1:
- print("Please enter your new password")
- newPass = input("")
- login_info[userloc][1] = newPass
- with open("Accounts.txt", 'w') as of:
- for pair in login_info:
- of.write(pair[0] + " " + pair[1] + "\n")
- else:
- menu()
- def userInformation():
- print(login_info[0], ",here is your registered information:\n")
- for line in open("UserInformation.txt","r").readlines():
- user_info = line.split()
- print("Your name is:",user_info[0])
- print("Your e-mail is:",user_info[1])
- print("Your date of birth is:",user_info[2])
- print("\n Press 1 to return to the main menu")
- selection = int(input())
- if selection == True:
- menu()
- def passCheck():
- pass
- mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement