is there a reason why my code just doesn't break and does what i want and just immediately goes to the else function even tho it wasnt not inputed?
Code:
import hashlib
def signup():
Username = input("Please input a username: ")
password = input("Please input a password: ")
Conf_password = input("Please confirm the password that you just entered: ")
if Conf_password == password:
enc = Conf_password.encode()
hash1 = hashlib.md5(enc).hexdigest()
with open("storage.txt", "w") as f:
f.write(Username + "\n")
f.write(hash1)
f.close()
print("You have registered successfully")
else:
print("Passwords do not match. Please try again.")
def login():
Username = input("Username: ")
password = input("Password: ")
auth = password.encode()
auth_hash = hashlib.md5(auth).hexdigest()
with open("storage.txt", "r") as f:
stored_username, stored_password = f.read().split("\n")
f.close
if Username == stored_username and auth_hash == stored_password:
print("You have logged in successfully!")
else:
print("Login Failed! \n")
logged_in = False
while True:
print("************** Login System ")
print("1.Signup")
print("2.Login")
print("3.Exit")
print("****************************")
ch = int(input("Please choose an option: "))
if ch == 1:
signup()
elif ch == 2:
logged_in = login()
if logged_in:
print("hi")
break
elif ch == 3:
break
else:
print("Invalid Choice!!")
whenever i use any of the functions (login or the signup) it does what it is supposed to but goes to the else function and repeats the while function.