Question

In: Computer Science

Question3: Consider you have the following data for some user accounts: [6 marks] Username Password User1...

Question3: Consider you have the following data for some user accounts: [6 marks]


Username

Password

User1

101010

User2

112121

User3

211211

User4

312132


1. Write a function called validate which takes 2 arguments: a dictionary, a username, and a password. The function should do the following: [3 marks]

Find the given username in the dictionary and compare the given password with the one that belongs to that username in the dictionary. Return true if password is correct and false if password is wrong for that username.

2. Create a dictionary called users containing the data given in above table. [2 marks]

3. Call the validate function and pass the users dictionary along with any username and password of your choice to test the function. [1 marks]

Solutions

Expert Solution

Please look at my code and in case of indentation issues check the screenshots.

---------------main.py--------------------------


#validate takes a dictionary, a username, and a password
def validate(usersDict, username, password):
   if username in usersDict.keys():       #Find the given username in the dictionary
       if usersDict[username] == password:   #compare the given password with the one that belongs to that username
           return True                    #Return true if password is correct
   return False                            #false if password is wrong for that username

#Create a dictionary called users containing the data given in above table
usersDict = {'User1': '101010', 'User2' : '112121', 'User3' : '211211', 'User4' : '312132'}


username = input("Enter a username: ")
password = input("Enter a password: ")
print(validate(usersDict, username, password))    #Call the function and pass the users dictionary, username, password

--------------Screenshots-----------------------

------------------Output----------------------

-----------------------------------------------------------------------------------------------------------
Please give a thumbs up if you find this answer helpful.
If it doesn't help, please comment before giving a thumbs down.
Please Do comment if you need any clarification.
I will surely help you.


Related Solutions

Write C++ code that prompts the user for a username and password (strings), and it calls...
Write C++ code that prompts the user for a username and password (strings), and it calls the login() function with the username and password as arguments. You may assume that username and password have been declared elsewhere. Your code should print error messages if login() generates an exception: LoginException: "Username not found or password incorrect" ServerException: "The login server is busy and you cannot log in" AccessException: "Your account is forbidden from logging into this server" Any other exception: "Unknown...
Write C++ code that prompts the user for a username and password (strings), and it calls...
Write C++ code that prompts the user for a username and password (strings), and it calls the login() function with the username and password as arguments. You may assume that username and password have been declared elsewhere. Use virtual functions, pure virtual functions, templates, and exceptions wherever possible. Please explain the code. Your code should print error messages if login() generates an exception: LoginException: "Username not found or password incorrect" ServerException: "The login server is busy and you cannot log...
The following times between keystrokes were recorded when a user typed the username and password: .23,...
The following times between keystrokes were recorded when a user typed the username and password: .23, .21, .27, .35, .33, .31, .34, .28, .20, .35, .31, .16, .16, .29, .39, .40, .35, .26 seconds. Let’s construct a 99% confidence interval for the mean time between keystrokes assuming Normal distribution of these times.
C++: Write a student class for the library, which have the following: Username, password, Maximum number...
C++: Write a student class for the library, which have the following: Username, password, Maximum number of copies that a student is allowed to keep(less than 5), maximum borrow periods(less than 30 days per book), list of copy(array) cpp and h
Discuss some of the successful user password policies that companies have used for their networks. What...
Discuss some of the successful user password policies that companies have used for their networks. What are some of the challenges that a company faces when it attempts to implement a very secure and stringent password policy?
PLEASE ANSWER WASNT ANSWERED PYTHON You will ask 3 questions USERNAME = "user1" PASSWORD = "password1"...
PLEASE ANSWER WASNT ANSWERED PYTHON You will ask 3 questions USERNAME = "user1" PASSWORD = "password1" What is your user name? What is your password? What is your age? If the user name and password are incorrect, display a message that says - Your credentials are not valid If both user name and password are correct, ask question 3 If the answer to question 3 is eighteen and greater, display a message that says - You're considered an adult If...
QUESTION3 Marks Consider two assets having equal weights in the portfolio (W1 = 0.50; W2 =...
QUESTION3 Marks Consider two assets having equal weights in the portfolio (W1 = 0.50; W2 = 0.50) and each asset has a standard deviation of 0.10. Using the above information, calculate: (a) the covariance of the portfolio for each of the five cases below. (b) the standard deviation of the portfolio for each of the five cases below. (c) Which of these cases guarantees an investor a complete risk-free portfolio? a. r1,2 = 1.00 b. r1,2 = 0.50 c. r1,2...
An attacker has obtained the user ID and password of a data center's backup operator and...
An attacker has obtained the user ID and password of a data center's backup operator and has gained access to a production system. Which of the following would be the attacker's NEXT action? A.Perform a passive reconnaissance of the network. B.Initiate a confidential data exfiltration process C.Look for known vulnerabilities to escalate privileges D.Create an alternate user ID to maintain persistent access
Question 6 - Week 11 (11 marks) Consider each of the following independent situations which have...
Question 6 - Week 11 Consider each of the following independent situations which have come to your attention. In each of the following independent and material situations assume that the client is a reporting entity and that a general-purpose financial report has been prepared and audited: Event 1: Part of Steel Limited's operations are in South America. Recent changes of government have made it impossible for you to verify the key accounts of inventory, fixed assets and cash and related...
PYTHON Exercise 3. Password locker. 1. You probably have accounts on many different websites. It’s a...
PYTHON Exercise 3. Password locker. 1. You probably have accounts on many different websites. It’s a bad habit to use the same password for each of them because if any of those sites has a security breach, the hackers will learn the password to all of your other accounts. Develop a simple password manager software on your computer where you write the account name (blog, facebook, instagram, etc) as an argument and the password is copied to the clipboard. Then...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT