I am producing a turn based game for a project and would like to create a user login system that saves the user's login username and password into a file in the game folder location. I would hope to then use the notepad file to check if there is already an account with that username when new users try to create a login.
In this code i attempted this but it is wrong?!
filename = 'UserInfo.txt'
openfile = open(filename, "r")
UserData = openfile.readline()
status = input("Are you a registered user? y/n? ")
if status == "y":
elif status == "n":
createLogin = input("Create login name: ")
if createLogin in UserData:
print ("Login name already exist!")
createPassw = input("Create password: ")
UserData[createLogin] = open('UserInfo','w')
login = input("Enter login name: ")
passw = input("Enter password: ")
if login in UserData and UserData[login] == passw:
print ("Login successful!")
print ("User doesn't exist or wrong password")
You should really be putting the error message up but I think I have spotted what is wrong. In
newUser() you are opening
'UserInfo.txt' also open in a mode not w mode. So write
You also need to read all the lines not just one line
Also remember to close the file after you open it in read mode or else it wont let you write to it:
openfile = open(filename, "r") UserData = openfile.readline() openfile.close();