Question: Help me fix this Username and Password checking code: User is to input the number of users, and then assign Usernames and Passwords to those

Help me fix this Username and Password checking code: User is to input the number of users, and then assign Usernames and Passwords to those Usernames. Then the user is brought to a 'log in screen' and are asked for a Username and a Password. If the combination of Username and Password match the previously initialized combinations, then they can log in and the program closes. If not, they are asked to try and log in again.

I have written out this code, however, it only works for the last stored Username + Password combination. It doesn't seem like it stores the previous ones. I know that making a list would do the job but I don't know how to go about it.

Here is my code (Python):

login = False userInput = int(input("How many users exist in this system?: ")) print(" [Initializing the Users and their Passwords]") for i in range(userInput): n = 0 if n<= userInput: name = str(input("Enter User " + str(i+1) +"'s Username: ")) password = str(input("Enter " + str(name) +"'s Password: ")) print("") n += 1 name_and_password = name + password print(" [Log in Screen]") userName = str(input("Enter Username: ")) userPassword = str(input("Enter " + userName + "'s Password: ")) userName_and_UserPassword = str(userName + userPassword) while login == False: if name_and_password == userName_and_UserPassword: print(" Correct User and Password Combination! You are now logged in.") login = True else: print(" Incorrect Username and Password combination. ") userName = str(input("Enter Username: ")) userPassword = str(input("Enter " + userName + "'s Password: ")) userName_and_UserPassword = str(userName + userPassword) login = False

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!