Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Josh Averill 10/09/2018 Nea Task Version one (Login)
- import random
- UsernamePassword = []
- UsefulList = []
- #Lists used to store data for passwords as well as checking them
- with open("UsernamePassword.csv") as DataFile:
- for EachLine in DataFile:
- EachLine=EachLine.strip()
- EachColumnItem = EachLine.split(",")
- UsernamePassword.append(EachColumnItem)
- def MainProgram():
- Dice_Roll()
- def Dice_Roll():
- DiceRoll = str(input("Do you want to roll the dice?"))
- if DiceRoll == "yes":
- print("Your number is: " + str(random.randint(1,6)))
- MainProgram()
- else:
- print("System failure, please contact developer.")
- def Username():
- Firstname = str(input("What is your firstname?"))
- Age = str(input("How old are you"))
- username = Firstname[:3]+Age
- print("Your username is:", username)
- return username
- #Function To create a username for new users
- def Password():
- password = str(input("What would you like your password to be"))
- return password
- #Asks new user for password of their choice
- def NewLogin(UsernamePassword,UsefulList):
- username = Username()
- password = Password()
- UsefulList.append(username)
- UsefulList.append(password)
- UsernamePassword.append(UsefulList)
- with open("UsernamePassword.csv", "w") as DataFile:
- for EachList in UsernamePassword:
- for EachItem in EachList:
- DataFile.write(EachItem + ",")
- DataFile.write("\n")
- #^^^^^^^ New login function creates and saves a new user profile
- def Login(UsernamePassword,UsefulList):
- WhewHew = 0
- username = str(input("What is your username"))
- password = str(input("What is your password"))
- for EachList in UsernamePassword:
- if username and password in UsernamePassword[WhewHew]:
- Row = WhewHew
- print("Username and password correct Welcome to the dice game")
- Dice_Roll()
- else:
- WhewHew = WhewHew+1
- print("Username Incorrect")
- Login(UsernamePassword,UsefulList)
- #^^^^^ Login function manages the Login for current users checking a external file to authenticate their login
- NewUser = str(input("Are you a new user?"))
- NewUser = str.upper(NewUser)
- if NewUser == "NO":
- Login(UsernamePassword,UsefulList)
- elif NewUser == "YES":
- NewLogin(UsernamePassword,UsefulList)
- print("Time to Login")
- Login(UsernamePassword,UsefulList)
- else:
- print("Please enter yes or no")
- Login(UsernamePassword,UsefulList)
- #This short section of code is what checks if the user is new or not
Add Comment
Please, Sign In to add comment