Python Forum
Please help me with my Bootcamp Homework...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help me with my Bootcamp Homework...
#6
I too have run into a wall with the second part of this assignment.

2. Create a function named getCreds with no parameters that will prompt the user for their username and password. This function should return a dictionary called userInfo that looks like the dictionaries below:
3. Create a function named checkLogin with two parameters: the userInfo and the adminList. The function should check the credentials to see if they are contained within the admin list of logins. The function should set a variable loggedIn to True if the credentials are found in the admin list, and set the variable to False otherwise.

Now that we know how to check to see if a user is logging in with admin credentials, let's set up the part of the system that will continue to prompt the user for their username and password if they didn't enter correct admin credentials before.

4. Create a while loop that will continue to call getCreds and checkLogin until a user logs in with admin credentials.

5. After each call of checkLogin in the while loop, print to the terminal the string "---------".

6. Once the user logs in with admin credentials, print to the terminal the string "YOU HAVE LOGGED IN!".

What I have written so far below:
# Administrator accounts list
adminList = [
    {
        "username": "DaBigBoss",
        "password": "DaBest"
    },
    {
        "username": "root",
        "password": "toor"
    }
]

# Build your login functions below
# creates a function called getCreds with no paramaters
def getCreds():
    #Prompts user for their username and password
    username = input("What is your username? ")
    password = input("What is your password? ")

    #Dictionary that retains username and password 
    userInfo = [
        {
            "username" : username, 
            "password" : password
        }
    ]
    #Return userInfo
    return userInfo

def checkLogin(userInfo, adminList):
    
    if userInfo in adminList:
        loggedIn = True

    else: 
        loggedIn = False

    while loggedIn == False:
        print("Login Failed. ")
        retry = getCreds()
        return retry

getCreds()

checkLogin()
I am having trouble wrapping up the credential check with a loop, though where I went wrong may even be before this part.

Errors I have received.
Error:
Traceback (most recent call last): File "c:/Users/Owner/Desktop/UserAdmin.py", line 45, in <module> checkLogin() TypeError: checkLogin() missing 2 required positional arguments: 'userInfo' and 'adminList'
Reply


Messages In This Thread
RE: Please help me with my Bootcamp Homework... - by km3 - Apr-15-2019, 08:12 PM

Forum Jump:

User Panel Messages

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