Question

In: Computer Science

Create a function named getCreds with no parameters that will prompt the user for their username...

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: # Administrator accounts list adminList = [ { "username": "DaBigBoss", "password": "DaBest" }, { "username": "root", "password": "toor" } ] 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. Create a while loop that will continue to call getCreds and checkLogin until a user logs in with admin credentials. After each call of checkLogin in the while loop, print to the terminal the string "---------". Once the user logs in with admin credentials, print to the terminal the string "YOU HAVE LOGGED IN!". Run the code often as you write and test individual functions with correct and incorrect admin credentials to make sure you're on the right path!

Solutions

Expert Solution

'''

Python version : 2.7

Python program to simulate user login

'''

# function to get user credentials and return it as a dictionary userInfo

def getCreds():

               username = raw_input('Username : ')

               password = raw_input('Password : ')

              

               userInfo = {"username":username,"password":password}

              

               return userInfo

# function to check if the user was able to login as admin i.e check the user credentials matches one of the credentials in adminList         

def checkLogin(userInfo,adminList):

              

               loggedIn = False

               # loop over adminList

               for user in adminList:

                              # check if username and password matches

                              if((userInfo["username"] == user["username"]) and (userInfo["password"] == user["password"])):

                                             loggedIn = True # set loggedIn to True if it matches

                                             break

                                            

               return loggedIn # return loggedIn

# main program

# initialize an adminList of admin user's credentials

adminList = [ { "username": "DaBigBoss", "password": "DaBest" }, { "username": "root", "password": "toor" } ]

loggedIn = False # set loggedIn to False

# loop that continues till the user is not able to login

while not loggedIn:

               userInfo = getCreds() # get user credentials

               loggedIn = checkLogin(userInfo,adminList) #check user credentials

               #check if user was able to login

               if loggedIn:

                              print('YOU HAVE LOGGED IN!')

                             

               print('--------------------------------------')    

#end of program             

Code Screenshot:

Output:


Related Solutions

python practice! 1. Create a function that takes a user choice and one number as parameters...
python practice! 1. Create a function that takes a user choice and one number as parameters and returns the operation result. -Square: print the number square -Sqrt: print the square root of the number -Reverse: reverse the sign of the number (pos or neg) and print it Note: Detect invalid choices and throw an error message – Number can be anything. 2. Create a function that takes a user choice and two numbers (start and end) as parameters. For example,...
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
Part I: Prompt the user for a single string and store it in a variable named...
Part I: Prompt the user for a single string and store it in a variable named userString. a. Use a for loop to print the string, char by char, with a dash '-' char between each. b. Use a for loop to print the string backwards, char by char, with a dash '-' char between each. Part II: Create an array of 5 strings named userStrings. Use a generalized array size. const int n = 5; string userStrings[n]; a. Populate...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
Prompt the user for their name, get and store the user input. Prompt the user for...
Prompt the user for their name, get and store the user input. Prompt the user for their age, get and store the user input. We will assume that the user will enter a positive integer and will do no error checking for valid input. Determine and store a movie ticket price based on the user's age. If their age is 12 or under, the ticket price is $5. If their age is between 13 and 64, inclusive, the ticket price...
Define a Python function named matches that has two parameters. Both parameters will be lists of...
Define a Python function named matches that has two parameters. Both parameters will be lists of ints. Both lists will have the same length. Your function should use the accumulator pattern to return a newly created list. For each index, check if the lists' entries at that index are equivalent. If the entries are equivalent, append the literal True to your accumulator. Otherwise, append the literal False to your accumulator. Hint: Since you must use the same index with each...
This program will function exactly the same as Ponder 02. It prompt the user for a...
This program will function exactly the same as Ponder 02. It prompt the user for a filename. We will then read the contents of the file into a list. The program will then prompt the user for a name. Finally, we will tell the user whether the name is in the list. Read From a File The first part of the program will be to read the contents of a file into a list. This data will be in JSON....
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the...
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the maximum number (as integer) Store a multiplication table for all combinations (with some specific eliminations) of value 0 through the maximum number (being entered) into a 2-D array Write a method named printTable to print out the MulitTable, with the following header, public static void printTable(int[][] multitable) In printTable(), when the value of the MultiTable is an odd number, print out Z Must use...
Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the...
Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the number of Adult tickets to purchase Prompt user to input the number of Children tickets to purchase Prompt user to input the number of Senior tickets to purchase Write a method named, ticketCost(), which will be invoked by main() with statement similar to: cost = ticketCost( adults, children, senior ); Ticket costs structure: $15.00 for each adult $10.00 for each child $5.00 for each...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT