#๐Ÿ”’ My code doesnt break.

6 messages ยท Page 1 of 1 (latest)

halcyon ledge
#

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.

sullen bisonBOT
#

@halcyon ledge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

halcyon ledge
#

nvm i fixed it

#

!close

sullen bisonBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.