Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- /**List of variables that will make the program symastically rich*/
- using userInput = std::string;
- using convertTo = std::string;
- using generatedPassword = std::string;
- using created = std::string;
- using wantingNewPassword = std::string;
- using countingChar = int;
- using yourPassword = bool;
- /**List of defined functions that will be used in code*/
- void passwordDirections(); //This function writes the directions for our user to make a password
- userInput userEnterName(); //This function will ask the user to enter their name so we can generate a password
- convertTo inputNameLessThan6(userInput userName); //This is checking to make sure the input is less than six to see if there is a bad password
- convertTo changeCharCase(userInput userName); //This will change the character case (i.e. lower/upper case)
- convertTo noSpaceInName(userInput userName); //This will take out the spaces of the user name
- convertTo noPunctuation(userInput userName); //This will get rid of the punctuation in the user input
- convertTo reverseName(userInput userName); //This will reverse the name that the user gave us so we can generate an automated password
- generatedPassword autoGeneratedPassword(userInput userName, countingChar charCount); //This will auto generate a password from the qualifications that are needed
- void changingPassword(generatedPassword autoPassword); //This will allow the user to change the password if they do not like the one that was generated for them
- void newPassword(generatedPassword autoPassword); //This allows our user to enter a new password
- void passwordIsWrong(std::string automatedPassword); //This will read off the information again if the password they entered was wrong
- //This will read off the directions to the user
- void passwordDirections () {
- std::cout << "***********************************************************************************" << std::endl;
- std::cout << "* Welcome! To make a password, here are the qualifications: *" << std::endl;
- std::cout << "* 1. The password should be a least 6 characters long. *" << std::endl;
- std::cout << "* 2. The password should contain at least one uppercase and one lowercase letter. *" << std::endl;
- std::cout << "* 3. The password should contain at least one digit. *" << std::endl;
- std::cout << "***********************************************************************************" << std::endl;
- }
- //This will ask the user to enter their name
- userInput userEnterName() {
- userInput userName;
- std::cout << "Enter your full name, including middle initial. ";
- std::getline(std::cin, userName);
- return userName;
- }
- //This will check if the inputted name is less than 6 chars, then replace with 6 to make up the difference
- convertTo inputNameLessThan6(userInput userName) {
- created replaceName{"666666"};
- for (countingChar i{0}; i < userName.length(); i++) {
- replaceName[i] = userName[i];
- }
- return replaceName;
- }
- //This will change the character case (i.e. lower/upper case)
- convertTo changeCharCase(userInput userName) {
- countingChar firstSpace, secondSpace;
- for (countingChar i{1}; i <= userName.length(); i++) {
- userName[i] = tolower(userName[i]);
- }
- firstSpace = userName.find(" ");
- secondSpace = userName.find(" ", firstSpace + 1);
- char first = userName[0];
- char second = userName[firstSpace + 1];
- char third = userName[secondSpace + 1];
- userName[0] = toupper(first);
- userName[firstSpace + 1] = toupper(second);
- userName[secondSpace + 1] = toupper(third);
- return userName;
- }
- //This will take out the spaces of the user name
- convertTo noSpaceInName(userInput userName) {
- created temporaryName{};
- for (const auto c: userName) {
- if (!isspace(c)) {
- temporaryName.erase(c);
- }
- }
- userName = temporaryName;
- return userName;
- }
- //This will get rid of the punctuation in the user input
- convertTo noPunctuation(userInput userName) {
- created temporaryName{};
- for (const auto c: userName) {
- if (!ispunct(c)) {
- temporaryName.push_back(c);
- }
- }
- userName = temporaryName;
- return userName;
- }
- //This will reverse the name and output the auto-generated password
- convertTo reverseName(userInput userName) {
- created nameBackwards{} ;
- for (countingChar i = userName.size() -1; i >= 0 ; i--) {
- nameBackwards += userName[i];
- }
- return nameBackwards;
- }
- //This is the function that will auto-generate a password for the user.
- generatedPassword autoGeneratedPassword(userInput userName, countingChar charCount) {
- generatedPassword autoPassword, CharCount = std::to_string(charCount);
- if (userName.length() < 6) {
- autoPassword = inputNameLessThan6(userName);
- std::cout << "Your auto-generated password is: " << autoPassword << std::endl;
- return autoPassword;
- }
- autoPassword = userName + CharCount;
- std::cout << "Your auto-generated password is: " << autoPassword << std::endl;
- return autoPassword;
- }
- //This will allow the user to change the password if they do not like the one that was generated for them
- void changingPassword(generatedPassword autoPassword) {
- wantingNewPassword changePassword;
- std::cout << "Would you like to change your password now [Y|N]? ";
- std::cin >> changePassword;
- if (changePassword == "n" || changePassword == "N") {
- std::cout << "Thank you. It is recommended that you change your password the next time you log into our system.";
- }
- else if (changePassword == "y" || changePassword == "Y") {
- newPassword(autoPassword);
- }
- else {
- std::cout<< "Invalid input, please try again" << std::endl;
- changingPassword(autoPassword);
- }
- }
- //This allows our user to enter a new password
- void newPassword(generatedPassword autoPassword) {
- created newPassword;
- yourPassword correctLength{false}, correctNumber{false}, correctUpper{false}, correctLower{false};
- std::cout << "Enter your password: ";
- std::cin >> newPassword;
- if (newPassword.length() >= 6) {
- correctLength = true;
- }
- for (countingChar i{0}; i < newPassword.length(); i++) {
- if (isdigit(newPassword[i])) {
- correctNumber = true;
- }
- if (isupper(newPassword[i])) {
- correctUpper = true;
- }
- if (islower(newPassword[i])) {
- correctLower = true;
- }
- }
- if (correctLength && correctNumber && correctLower && correctUpper) {
- std::cout << "Thank you. Please use your new password then ext time you log into our system.";
- }
- else {
- std::cout << "We are sorry. Your password does not meet our requirements: " << std::endl;
- if (correctLength == false) {
- std::cout << " * The password should be at least 6 characters long." << std::endl;
- }
- if (correctLower == false || correctUpper == false) {
- std::cout << " * The password should have at least one upper and one lower case letter." << std::endl;
- }
- if (correctNumber == false) {
- std::cout << " * The password does not contain at least one digit" << std::endl;
- }
- passwordIsWrong(autoPassword);
- }
- }
- void passwordIsWrong(generatedPassword automatedPassword){
- std::cout << "Your password was not changed. It remains: " << automatedPassword;
- std::cout << "nAs a reminder, your password shouldn" <<
- " * Be at least 6 characters longn" <<
- " * Contain at least one lower and uppercase lettern" <<
- " * Contain at least one digitn" <<
- "It is recommended that you change your password the next time you log into our system";
- }
- int main() {
- passwordDirections();
- userInput name = userEnterName();
- countingChar charCount = name.size();
- generatedPassword autoPassword = autoGeneratedPassword(reverseName(noPunctuation(noSpaceInName(changeCharCase(inputNameLessThan6(name))))), charCount);
- changingPassword(autoPassword);
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment