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?
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...
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...
1. Using Kerberos for authentication eliminates the need for a user to have a password for...
1. Using Kerberos for authentication eliminates the need for a user to have a password for each server or resource they want to access. True False 2. Secure hash functions provide data integrity, but not data authenticity . True False 3. Which of the following is an example of "Something you possess"? Key Face Recognition Finger print Password 4. ____________ enables the sharing of identities across different enterprises for user access to applications. Identity Federation Kerberos Realm Public-key infrastructure Multifactor...
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
In python language do thee following: Some password scheme is designed such that the password must...
In python language do thee following: Some password scheme is designed such that the password must start with a special symbol in “$” “@” or “!” followed by four letters that could be in a..z followed by a similar special symbol followed by three letters in A..Z followed by a single digit. Write a program that takes from the user a string, and verifies whether the string abides by this password scheme. Do this once using regular expressions. Another time...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT