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

2. Create a new project named named lab5_2. You will prompt the user for an amount...
2. Create a new project named named lab5_2. You will prompt the user for an amount of names to enter, and then ask for that amount of names. You’ll store these names in a vector of strings. Then you’ll sort the vector. Finally, you’ll print the results. How many names?: 4 Enter a name: Leonardo Enter a name: Donatello Enter a name: Michelangelo Enter a name: Raphael ==================== Alphabetized ==================== Donatello                  Leonardo Michelangelo                      Raphael
Create a file named sales_bonus.py 2. Prompt the user for the amount of sales made, convert...
Create a file named sales_bonus.py 2. Prompt the user for the amount of sales made, convert to a float, and assign to sales. 3. Prompt the user for number of days missed, covert to an int, and assign to days_missed 4. If the user have more than 3000 of sales and has missed less than or equal to two days of work, assign bonus to 100. 5.   Else if the user have more than 3000 of sales or has missed less...
python Create a file named sales_bonus.py 2. Prompt the user for the amount of sales made,...
python Create a file named sales_bonus.py 2. Prompt the user for the amount of sales made, convert to a float, and assign to sales. 3. Prompt the user for number of days missed, covert to an int, and assign to days_missed 4. If the user have more than 3000 of sales and has missed less than or equal to two days of work, assign bonus to 100. 5.   Else if the user have more than 3000 of sales or has missed...
Create a Visual Studio console project named exercise101. The main() function should prompt for the name...
Create a Visual Studio console project named exercise101. The main() function should prompt for the name of a text file located in the same directory as exercise101.cpp, and search for a word in the text file as follows: Enter text file name: Enter search word: The program should print the number of occurrences of the word in the file: occurrences of were found in If the file could not be opened then display: File not found Use Stream file I/O...
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....
5) Create the following in a Java program Create a scanner Prompt the user to enter...
5) Create the following in a Java program Create a scanner Prompt the user to enter the name where the box of mail is shipping from and create the variable and relate to scanner Prompt the user to enter the name of destination where the box of mail will be shipped and create the variable and relate to scanner Prompt the user to enter the weight of the package and create variable to relate to scanner Calculate cost of shipping...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT