its a username/password log in an external file but it only stores some stuff and doesnt work properly.It adds the second username twice even though its already in the file and if i do it so the first input was in the file and the second one wrong, then it works. It also works sometimes.
I want the code to store the username and password (togther) if the username isnt in the fils and just print"Validtaed" if the username and password is in teh file.
I want the code to store the username and password (togther) if the username isnt in the fils and just print"Validtaed" if the username and password is in teh file.
import sys username1 = input("Player one enter an existing or new username of 8 characters: ") if len(username1)== 8: you = 2 else: print("Invalid username try again") sys.exit() password1 = input("Player one enter an existing or new password of 4 characters: ") if len(password1)== 4: you = 2 else: print("Invalid password try again") sys.exit() username2 = input("Player two enter an existing or new username of 8 characters: ") if len(username2)== 8: you = 2 else: print("Invalid username try again") sys.exit() password2 = input("Player two enter an existing or new password of 4 characters: ") if len(password2)== 4: you = 2 else: print("Invalid password try again") sys.exit() usernameandpassword1 = username1+password1 usernameandpassword2 = username2+password2 #Checks if Username and Password are already known file = open("Users.txt","r") print(file.read()) for TextLine in file: if usernameandpassword1 in TextLine: FoundPhrase = TextLine print("Validated Password.") break else: #if the username and password isnt known itll add the account to the file with open('Users.txt', 'a') as tf: tf.write("\n"+ usernameandpassword1) print("Your account has been added.") #same for user 2 f = open("Users.txt","r") for Test in f: if (usernameandpassword2 in Test)== True: FoundPhrase = Test print("Validated Password.") break else: with open('Users.txt', 'a') as tf: tf.write("\n"+ usernameandpassword2) print("Your account has been added.") break