So I just started learning python and tried a little project that consists of a login system. I want usernames and passwords to save into .txt files but they just won't and I can't figure out the error. The issue must be happening in the register dunction that I've defined because login works just fine with the username and password that I've introduced manually.
def register():
user = input("Registration page\nUSERNAME:")
users = open("users.txt", "r")
if user in users:
print("That user already exists!")
login()
users.close()
else:
pwrds = open("pass.txt", "a")
users = open("users.txt", "a")
users.write("\n" + user)
p1 = input("PASSWORD:")
p2 = input("CONFIRM PASSWORD:")
if p1 == p2:
pwrds.write("\n" + p1)
login()
users.close()
pwrds.close()
else:
print("Failed password confirmation, restarting")
register()
users.close()
pwrds.close()
Thank you in advance for the help!