I am trying to create a code where two pre-existing users can login to an account, and it is authorized from a csv file - these players can then play a dice game. I have completed the game, however my code doesn't read my loop with the information for reading the csv in. I have tried many different ways, including simply reading the rows alone, splitting the lines, and many other things. My code doesn't return any errors, instead just runs the code, without authenticating the users. I will need the code to search for the username, if it exists check if the password in the box to the immediate right matches the password given from the code, print the user is logged in. If the user and password don't match, let the user enter the password a further two times, and if the password still doesn't match print they can't login.
Any help would be appreciated, thank you.
import csv #importing my csv with my authenticated users in
import random #importing random to use to generate a random number
def login1(): #creating a function so i can do the login cycle again
loggedin1 = False #making user1 not logged in
global username
username = input("Please enter your username:")# ask the users username
password = input("Please enter your password:")#ask user for password
with open("game.csv","r+")as csvfile: # opening my csvfile
datareader = csv.reader(csvfile, delimiter=',') #reading my csv file
for row in datareader:
user = line.split(",")
user = user[0]
print(user) # to test if it is running this
if username == user:
print("User name exists")
for row in datareader:
passw = line.split(",")
passw = passw[0]
if password == passw:
print("hello",username,"you are logged in")
else:
password =input("Password is wrong, please try again")
elif userexists == False:
print("no username found, please enter the username again")
login1()
return(username)
login()
question from:
https://stackoverflow.com/questions/65934831/python-my-code-doesnt-loop-into-the-for-loop-to-read-the-csv 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…