Python Forum
in a login interface when i try login with a user supposed to say test123 but nothing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
in a login interface when i try login with a user supposed to say test123 but nothing
#1
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.
Larz60+ write Feb-20-2021, 04:08 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Fixed for you this time. Please use bbcode tags on future posts.
Reply
#2
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.
Reply
#3
You might want to look at: https://pypi.org/search/?q=login
Looks like this might do the trick: https://pypi.org/project/login/
Reply
#4
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")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Database connection problems [login, PyQt5, PySql] gradlon93 5 620 Dec-15-2023, 05:08 PM
Last Post: deanhystad
  Help on the User Interface Afia 1 504 Jul-21-2023, 07:22 PM
Last Post: snippsat
  [Solved]Help with SQLite Login Form Extra 7 1,836 Jun-25-2022, 10:53 AM
Last Post: deanhystad
  user interface Button not working Frankduc 4 1,418 Feb-16-2022, 02:52 PM
Last Post: Frankduc
  Python class doesn't invoke setter during __init__, not sure if's not supposed to? mtldvl 2 3,246 Dec-30-2021, 04:01 PM
Last Post: mtldvl
  Avoiding Re-login Goodsayan 0 1,341 Sep-09-2021, 01:53 PM
Last Post: Goodsayan
  Login through a protected directory ebolisa 3 2,003 Jul-24-2021, 09:12 PM
Last Post: ebolisa
  Login to NordVPN on Linux with python script AGreenPig 2 5,912 Feb-09-2021, 10:44 AM
Last Post: AGreenPig
  Help with User Interface design code ai_masti 0 1,900 Nov-19-2020, 05:58 PM
Last Post: ai_masti
  want to make auto login with data R3born 3 2,179 Sep-11-2020, 07:06 PM
Last Post: R3born

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020