Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Python) Username and password creation exercies print(----------------------------------------------) print( tCreate Account ) username = input(Please enter a new username: ) Check if username consists of

(Python) Username and password creation exercies print("----------------------------------------------") print(" \tCreate Account ") username = input("Please enter a new username: ") """ Check if username consists of only characters from A - Z or a - z; if not, keep asking the user to enter a valid new username.""" # 1) VALIDATION CODE FOR USERNAME GOES HERE password = input("Please enter a new password: ") """ Check if password consists of only characters or digits; if not, keep asking the user to enter a valid new password.""" # 2) VALIDATION CODE FOR PASSWORD GOES HERE print(" Account created! ") run = True tries_left = 3 while run is True: # while run is true, program will keep asking for sign in login_success = False login_check = input("Would you like to log in? (y/n): ") if login_check.lower() == 'y': # .lower() converts input to lowercase print("You will have 3 attempts.") '''1. For the for loop below, It should loop 3 times, once for each attempt. ''' tries_left = 3 for attempt_num in range( tries_left): # Alternatively you can change this into a while loop if you prefer to use a while structure print(" ---------------------------------------------- ") print("\tLogin ") check_user = input("Username: ") check_pw = input("Password: ") # if login information is correct if (check_user == username and check_pw == password): print(" Login succeeded!") print(" ---------------------------------------------- ") login_success = True break # this break stmt, if reached, program will exit the for loop else: # if login information is incorrect print("Incorrect credentials.") tries_left -= 1 print(' You have', tries_left, 'attempts remaining.') if tries_left == 0: run = False break while login_success is True: # if login is successful, go to menu print("\tMenu ") print("1. Change Username") print("2. Change Password") print(" Press any other key to log out.") choice = input(" Enter number of a menu option: ") print(" ---------------------------------------------- ") if choice == "1": # if user selects Change Username print("\tChange Username ") """Ask the user to enter their username and password:""" check_user = input("Enter your current username: ") check_pw = input("Enter your current password: ") ''' COMPLETE THIS SECTION 1. Check to see if username and password are correct 2. Prompt user for a new username 3. Ask user to confirm username 4. If the new username and confirmation match, tell the user that their username is changed, print out their new username,and return to menu. If they don't match, tell the user that the usernames did not match and return to the menu NOTE: The program should handle any invalid input (wrong passwords, etc.). ''' # 3) USERNAME AND PASSWORD CHECK """ Check if username consists of only characters from A - Z or a - z; if not, keep asking the user to enter a valid new username.""" # 4) USERNAME VALIDATION print(" ---------------------------------------------- ") elif choice == "2": # if user selects Change Password print("\tChange Password ") """Ask the user to enter their username and password:""" check_user = input("Enter your current username: ") check_pw = input("Enter your current password: ") ''' COMPLETE THIS SECTION 1. Check to see if username and password are correct 2. Prompt user for a new password 3. Ask user to confirm password 4. if the new password and confirmation match, tell the user that their password is changed and return to menu. If they don't match, tell the user that the usernames did not match and return to the menu. NOTE: The program should handle any invalid input (wrong passwords, etc.) ''' # 5) USERNAME AND PASSWORD CHECK """ Check if password consists of only characters or digits; if not, keep asking the user to enter a valid new password.""" # 6) PASSWORD VALIDATION print(" ---------------------------------------------- ") else: # This section is reached if user does not enter 1 or 2 at menu login_success = False print("Logging out...") print(" ---------------------------------------------- ") else: # this is reached when the user does not enter y or Y at login prompt run = False # This line is only reached after the user chooses to exit the program # This is outisde of the main loop input("Program exiting, press any key to continue...") quit() # This Python function terminates execution of the script 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

What perspective or approach to talent would be appropriate?

Answered: 1 week ago

Question

What policies and practices for talent development are needed now?

Answered: 1 week ago