Python Forum

Full Version: in a login interface when i try login with a user supposed to say test123 but nothing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
SOLVED
first time in python forum
i would say im fairly intermidiate to python, so this problem happened:
my code:

#Toggling Off Shell
toggleonoff = False
users = []
passwords = []
account = {}
header = "loginshell.py: "
while toggleonoff == False:
	currenttype = input(header)
	if currenttype == "adduser":
		#Adding User Command
		users.append(print("Username is " + input("Please type in new username: ")))
		passwords.append(print("Password is " + input("Please type in your password: ") + ". Added account." ))
		account[users[len(users) - 1]] = passwords[len(passwords) - 1]
	elif currenttype == "login":
		#Logging In
		loguser = input("Type in which user to log in to: ")
		x = 0
		for user in users:
			if user == loguser:
				print("test123")
			elif x > len(users):
				break
			x=x+1
	elif currenttype == "exit":
		exit()
	else:
		print("Please try again. ")
so this program is basically a shell, but then for users to login. making as side project. when i add two new users, by typing in adduser, whioh command for adding new users and then i try to login with lets say the second user, its supposed to say test123 but instead it shows nothing. just the input for the looping. kind of hard to explain, but by the input of the loop,i mean that i made a loop that gives a input alwys until program ends. Using Python 3.9.1, in Sublime Text.
Can you edit your post and put the code in python tags (use the python button above the editor)? Without those tags, the indentation is lost.
You might want to look at: https://pypi.org/search/?q=login
Looks like this might do the trick: https://pypi.org/project/login/
You're looping on toggleonoff, but you never change it. Might as well just do a while True: loop.

Instead of saving the result of the username/password inputs, you're passing it to print(). Then you append the result of the print() to the users and passwords list. But the result of print() is always None, so the users and passwords are lost.

This section:
        x = 0
        for user in users:
            if user == loguser:
                print("test123")
            elif x > len(users):
                break
            x=x+1
Could probably be better written as

if loguser in users:
    print("test123")