Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

7.6 Module 5 ZyLab - Login Credentials (PYTHON) LAB OVERVIEW In this lab, you wi

ID: 3723369 • Letter: 7

Question

7.6 Module 5 ZyLab - Login Credentials (PYTHON)

LAB OVERVIEW
In this lab, you will create a program that allows a user to store login credentials. Your program will obtain user emails and passwords and will create a username and store them in parallel lists. Parallel lists allow you to store different types of related information in separate lists and reference them by the element ID.

Please note that each exercise below shows the program being run from the beginning. There is no need to repeat code for each exercise.

(1) Complete the getEmailAddress() function. This function has no parameters and returns a valid address. A valid email address is an address the contains both an "@" (ampersand) sign and a "." (period). If the user enters an invalid email address, the function should allow the user to re-enter a correctly formatted email address and loop until that correctly formatted address is received. We will not be concerned where the ampersand and periods are in the email address at this time. Remember to uncomment the function call in the main function. (15 Points)

Ex.

(2) Complete the getPassword() function. This function has no parameters and returns a valid password. A valid password contains at least one capital letter, one numeric character, and is at least 8 characters in length. If the user enters an invalid password, the function should allow the user to re-enter a valid password and loop until a valid password is received. You are not required to notify the user of why the password is invalid. Remember to uncomment the function call in the main function. (15 points)

Ex.

(3) Complete the getUsername() function. This function takes the email address as a parameter and returns a username. The username will consist of all of the characters preceding the ampersand. For example, if the email address is maywilson@gmil.com, then the username will be marywilson. Remember to uncomment the function call in the main function. (10 points)

(4) Store each of the login credential items in their respective lists. Once this process is complete, display a confirmation message. (5 points)

Ex.

(5) Complete the displayCredentialsReport() function. This function should take all 3 lists as parameters and produce a report of all of the available login credentials. You will simply need to create loop to iterate through the lists. (5 points)

Ex.

(PYTHON)

Explanation / Answer

import getpass

credentials = {} ## Sets up an array for the login credentials
with open('Usernames.txt', 'r') as f: ## Opens the file and reads it
for line in f: ## For each line
username, delim, password = line.strip().partition(':') ## Separate each line into username and password, splitting after a colon
credentials[username] = password.split(';') ## Links username to password

while True:
username = raw_input("Please enter your username: ") ## Asks for username
if username in credentials: ## If the username is in the credentials array
while True:
password = getpass.getpass("Please enter your password: ") ## Asks for password
if password == credentials[username][0]:
print "Logged in successfully as " + username ## Log in
break
elif password in credentials[username]: ## If the password is linked to the username
print "Specific error message " + username ## Log in
else:
print "Password incorrect!"
break
else:
print "Username incorrect!"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote