Question: Create a python script to manage a user list that can be modified and saved to a text file. Input text file consisting of pairs

Create a python script to manage a user list that can be modified and saved to a text file.

Input text file consisting of pairs of usernames and passwords, separated by a colon (:) without any spaces

User choice: (n-new user account, e-edit existing user account, d- delete existing user account, l- list user accounts, q-quit)

List of user accounts, error messages when appropriate

Output text file consisting of pairs of username and passwords, separated by a colon (:) without any spaces

The program maintains a list of user accounts and passwords supplied by a system administrator.

Any inputted username should be stripped of any non-alphanumeric characters (special characters such as ! @ # $ % ^ & * ( ) _ + ; : ) using: username = re.sub(r'\W+','',username) [You need to import the library "re"] and should be converted to lowercase: username = username.lower()

Any inputted password should be stripped of the apostrophe character ' using: password = password.replace('\'', '')

Each option should be implemented as a separate function within a Package that will be imported, so that its functions can be called. Valid options will be stored in a list to test for invalid options: function = [n, e, d, l, q]

The usernames and passwords will be loaded from an input file and stored in a dictionary (Pythons version of a hash). The dictionary will be passed as a parameter from the Python script file to the appropriate function in the module file and updated according to the function. The script file should import the functions from the module file to call the appropriate function.

Initially, the program prompts for an input text file to read from. If the file does not exist, it should be created. The program should then loop until the user chooses to quit (selects status as q). If the user enters an illegal status, the program will prompt again for the status input. Upon quitting, the program prompts the user to save the list to an output file with the same name as the original input text file. Sample output:

Enter file to open: myfile.txt 
User accounts ------------- n = New user account e = Edit existing user account d = Delete existing user account l = List user accounts q = Quit 
Enter choice: n Enter username: einstein Enter password: e=mc^2 
User accounts ------------- n = New user account e = Edit existing user account d = Delete existing user account l = List user accounts q = Quit 
Enter choice: n Enter username: newton Enter password: f=ma 
User accounts ------------- n = New user account e = Edit existing user account d = Delete existing user account l = List user accounts q = Quit 
Enter choice: n Enter username: pythagoras Enter password: a^2+b^2=c^2 
User accounts ------------- n = New user account e = Edit existing user account d = Delete existing user account l = List user accounts q = Quit 
Enter choice: n Enter username: einstein Username already exists! 
User accounts ------------- n = New user account e = Edit existing user account d = Delete existing user account l = List user accounts q = Quit 
Enter choice: e Enter username to modify: fibonacci Username does not exist! 
User accounts ------------- n = New user account e = Edit existing user account d = Delete existing user account l = List user accounts q = Quit 
Enter choice: e Enter username to edit: newton Enter current password: f=m*a Incorrect password! 
User accounts ------------- n = New user account e = Edit existing user account d = Delete existing user account l = List user accounts q = Quit 
Enter choice: e Enter username to edit: newton Enter current password: f=ma Enter new password: force=mass*accelaration 
User accounts ------------- n = New user account e = Edit existing user account d = Delete existing user account l = List user accounts q = Quit 
Enter choice: d Enter username to delete: pythagoras User removed 
User accounts ------------- n = New user account e = Edit existing user account d = Delete existing user account l = List user accounts q = Quit 
Enter choice: l einstein:e=mc^2 newton:force=mass*accelaration 
User accounts ------------- n = New user account e = Edit existing user account d = Delete existing user account l = List user accounts q = Quit 
Enter choice: q Save contents? (y/n): y % more myfile.txt einstein:e=mc^2 newton:force=mass*acceleration 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!