NEA login system using lists and index values

Hi, I am trying to make a login system where it links the index value of both lists (username and password) but I just can’t understand how to complete it.
The current code:

usernames = ["a","b","c"]
passwords = ["1","2","3"]
index = 0
while 1:
    user = input("Please enter your username:\t").lower()
    index = usernames.index(user)
    passw = input("Please enter your password:\t")      
    index = passwords.index(passw)

I need to link the index values and also somehow use an if statment if the input is incorrect.
By the way this text is indented after the while loop if it doesn’t show up

Hello and welcome to the forum :partying_face:!

Please, whenever you write code, put it between three back ticks ``` and ``` (unless it’s single line, in which case you can surround it with single back ticks).

For your problem, if you know that users and passwords are correlated by the index, then you just have to find the index of the user name:

# If the user doesn't exist an exception will be thrown
index = usernames.index(user)

# Compare if the passw equals to passwords[index]: passw == passwords[index], the user is allowed
# else it's the wrong password
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.