So after I login successfully in the account the code should stop running, but I don't know why that doesn't happened, it also should happened when i press "q". Also when I go to the second option(register) after I enter the username and then password, they don't instantly get written in the .txt file, but it gets written after I somehow end the code. Is there a way I can write the username and password immediately I write them and then in the same loop login?
Code:
database = open("database.txt", "r+")
status = True
def display_menu():
print("Login or Register?")
print("INFO: Press 1 for Login or 2 for Register\nPress q to exit!")
choice = input("Login/Register/Exit: ")
if choice == "1":
login()
elif choice == "2":
register()
elif choice == "q":
status = False
def login():
username = input("Enter your name: ")
password = input("Enter your password: ")
if username and password in database:
print("You have successfully login!")
status = False
else:
if password not in database and username in database:
print("Wrong password!")
elif username not in database and password in database:
print("Wrong username!")
else:
print("You don't have an account!")
def register():
create_username = input("Username: ")
database.write(str(create_username))
create_password = input("Password: ")
database.write(str(create_password))
confirmation_password = input("Confirmation Password: ")
if create_username in database:
print("The name is already taken")
elif confirmation_password != create_password:
print("Your passwords doesn't match!")
register()
else:
print("You have successfully created your account!\n")
print("Now you can log in!\n")
login()
while True:
display_menu()