A driver containing a main function that will allow the user to change their password. PasswordManager Class
Question:
A driver containing a main function that will allow the user to change their password.
PasswordManager Class
The PasswordManager class should have two member variables (both strings):
a username
an encrypted password. Do not store the password (in the class or in a text file) unencrypted!
The PasswordManager class should have the following two internal member functions (not accessible outside of the class):
encrypt: this takes a password (a string) and returns the encrypted form of the password. Note: there is no decrypt function (there is no need to decrypt passwords). We will use the following VERY simple encryption algorithm (a Caesar Cipher):
For every character in the input string, add 41 to the ascii value of the character. The encrypted character’s ascii value must stay in the range of printable, non-whitespace characters: 33 to 126. This can be enforced using this formula:
ascii value of encrypted char = ((ascii value of ch - 33) + 41) % 94 + 33
Store all the encrypted chars in a string and return it as the result of the function (hint: start with an empty string, use string.push_back(ch) to add each encrypted character).
meetsCriteria: this takes a string (a password) and returns true if it meets the following criteria:
it has at least 15 characters.
it contains at least one of each of the following categories:
uppercase letter (use isupper(ch))
lowercase letter (use islower(ch))
numbers (use isdigit(ch)) and symbols (use ispunct(ch))
If the criteria are not met, it returns false.
The PasswordManager should have the following member functions that are accessible from outside of the class (from the driver):
setUsername: (a setter function) takes a string and stores it in the proper member variable.
getUsername: (a getter function) returns the value of the proper member variable.
setEncryptedPassword: (a setter function) takes a string (an already encrypted password) and stores it in the proper member variable.
getEncryptedPassword: (a getter function) returns the value of the encrypted password stored in the proper member variable.
setNewPassword: takes a string (a proposed, unencrypted, password). If it meets the criteria in meetsCriteria, it encrypts the password and stores it in the member variable and returns true. Otherwise returns false.
authenticate: takes a string (a password) and returns true if, once encrypted, it matches the encrypted string stored in the the member variable. Else returns false.
Save the class declaration in PasswordManager.h and save the member function definitions in PasswordManager.cpp (do not inline the member function definitions).
Don't change names, parameters or return values of these methods. Otherwise you won't be able to pass all tests.
PasswordDriver
The main function should create an array of 4 instances of the PasswordManager class.
Your main function will ask for a filename to store the usernames and encryptedpasswords in between executions of the program. This file simulates the stored encrypted passwords for users of a computer system. You can download a sample “passwords.txt” file from the 'Additional files' section of this assignment. When your main function starts, it should try to open the file with the filename you provided. If the file exists, you should assume it contains 4 usernames with encrypted passwords, and the program should use these to set the usernames and encrypted passwords in the password manager array. If the file doesn’t exist, exit with an error message.
Your program should ask the user to enter the filename, their netID, old password, and new password:
Please enter the name of the input file: passwords.txt Please enter your netID: j_s108 Please enter your old password: abcdABCD1234!@#$ Please enter your new password: jjjhFdjdhyas555
Your program should give one of the following responses:
NetID is invalid, password not changed. Old password is incorrect. New Password does not meet criteria. Password has been changed for netID: j_s108
If any of the input data is invalid or causes an error message, do NOT ask the user to re-enter the data.
After outputting one of the above responses to the screen, the program should output the usernames and three encrypted passwords to the file that was used for input, one per line (overwriting anything that was previously in the file), then exit. However in order to simplify the testing procedure, please output this data directly to the screen instead.
There is a provided passwords.txt file with 4 sample usernames and encrypted password:(note that ,-./jklmZ[]JiLM is the encrypted version of abcdABCD1234!@#$).
NOTES:
Usernames and passwords do not contain any whitespace. When a user enters a password, assume a whitespace character indicates the end of the password.
Put a header comment at the top of each file.
ALL of the input and output must be done by the driver. The password manager class should not do ANY input/output, not to the screen OR the file!
Useful functions: isupper(char), islower(char), isdigit(char), ispunct(ch), string.length()