Guest User

Untitled

a guest
Nov 3rd, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.01 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. /**List of variables that will make the program symastically rich*/
  5. using userInput = std::string;
  6. using convertTo = std::string;
  7. using generatedPassword = std::string;
  8. using created = std::string;
  9. using wantingNewPassword = std::string;
  10. using countingChar = int;
  11. using yourPassword = bool;
  12.  
  13. /**List of defined functions that will be used in code*/
  14. void passwordDirections(); //This function writes the directions for our user to make a password
  15. userInput userEnterName(); //This function will ask the user to enter their name so we can generate a password
  16. convertTo inputNameLessThan6(userInput userName); //This is checking to make sure the input is less than six to see if there is a bad password
  17. convertTo changeCharCase(userInput userName); //This will change the character case (i.e. lower/upper case)
  18. convertTo noSpaceInName(userInput userName); //This will take out the spaces of the user name
  19. convertTo noPunctuation(userInput userName); //This will get rid of the punctuation in the user input
  20. convertTo reverseName(userInput userName); //This will reverse the name that the user gave us so we can generate an automated password
  21. generatedPassword autoGeneratedPassword(userInput userName, countingChar charCount); //This will auto generate a password from the qualifications that are needed
  22.  
  23. 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
  24. void newPassword(generatedPassword autoPassword); //This allows our user to enter a new password
  25. void passwordIsWrong(std::string automatedPassword); //This will read off the information again if the password they entered was wrong
  26.  
  27. //This will read off the directions to the user
  28. void passwordDirections () {
  29. std::cout << "***********************************************************************************" << std::endl;
  30. std::cout << "* Welcome! To make a password, here are the qualifications: *" << std::endl;
  31. std::cout << "* 1. The password should be a least 6 characters long. *" << std::endl;
  32. std::cout << "* 2. The password should contain at least one uppercase and one lowercase letter. *" << std::endl;
  33. std::cout << "* 3. The password should contain at least one digit. *" << std::endl;
  34. std::cout << "***********************************************************************************" << std::endl;
  35.  
  36. }
  37.  
  38. //This will ask the user to enter their name
  39. userInput userEnterName() {
  40. userInput userName;
  41. std::cout << "Enter your full name, including middle initial. ";
  42. std::getline(std::cin, userName);
  43. return userName;
  44. }
  45.  
  46. //This will check if the inputted name is less than 6 chars, then replace with 6 to make up the difference
  47. convertTo inputNameLessThan6(userInput userName) {
  48. created replaceName{"666666"};
  49. for (countingChar i{0}; i < userName.length(); i++) {
  50. replaceName[i] = userName[i];
  51. }
  52. return replaceName;
  53. }
  54.  
  55. //This will change the character case (i.e. lower/upper case)
  56. convertTo changeCharCase(userInput userName) {
  57. countingChar firstSpace, secondSpace;
  58. for (countingChar i{1}; i <= userName.length(); i++) {
  59. userName[i] = tolower(userName[i]);
  60. }
  61. firstSpace = userName.find(" ");
  62. secondSpace = userName.find(" ", firstSpace + 1);
  63. char first = userName[0];
  64. char second = userName[firstSpace + 1];
  65. char third = userName[secondSpace + 1];
  66. userName[0] = toupper(first);
  67. userName[firstSpace + 1] = toupper(second);
  68. userName[secondSpace + 1] = toupper(third);
  69. return userName;
  70. }
  71.  
  72. //This will take out the spaces of the user name
  73. convertTo noSpaceInName(userInput userName) {
  74. created temporaryName{};
  75. for (const auto c: userName) {
  76. if (!isspace(c)) {
  77. temporaryName.erase(c);
  78. }
  79. }
  80. userName = temporaryName;
  81. return userName;
  82. }
  83.  
  84. //This will get rid of the punctuation in the user input
  85. convertTo noPunctuation(userInput userName) {
  86. created temporaryName{};
  87. for (const auto c: userName) {
  88. if (!ispunct(c)) {
  89. temporaryName.push_back(c);
  90. }
  91. }
  92. userName = temporaryName;
  93. return userName;
  94. }
  95.  
  96. //This will reverse the name and output the auto-generated password
  97. convertTo reverseName(userInput userName) {
  98. created nameBackwards{} ;
  99. for (countingChar i = userName.size() -1; i >= 0 ; i--) {
  100. nameBackwards += userName[i];
  101. }
  102. return nameBackwards;
  103. }
  104.  
  105. //This is the function that will auto-generate a password for the user.
  106. generatedPassword autoGeneratedPassword(userInput userName, countingChar charCount) {
  107. generatedPassword autoPassword, CharCount = std::to_string(charCount);
  108. if (userName.length() < 6) {
  109. autoPassword = inputNameLessThan6(userName);
  110. std::cout << "Your auto-generated password is: " << autoPassword << std::endl;
  111. return autoPassword;
  112. }
  113. autoPassword = userName + CharCount;
  114. std::cout << "Your auto-generated password is: " << autoPassword << std::endl;
  115. return autoPassword;
  116. }
  117.  
  118. //This will allow the user to change the password if they do not like the one that was generated for them
  119. void changingPassword(generatedPassword autoPassword) {
  120. wantingNewPassword changePassword;
  121. std::cout << "Would you like to change your password now [Y|N]? ";
  122. std::cin >> changePassword;
  123. if (changePassword == "n" || changePassword == "N") {
  124. std::cout << "Thank you. It is recommended that you change your password the next time you log into our system.";
  125. }
  126. else if (changePassword == "y" || changePassword == "Y") {
  127. newPassword(autoPassword);
  128. }
  129. else {
  130. std::cout<< "Invalid input, please try again" << std::endl;
  131. changingPassword(autoPassword);
  132. }
  133. }
  134.  
  135. //This allows our user to enter a new password
  136. void newPassword(generatedPassword autoPassword) {
  137. created newPassword;
  138. yourPassword correctLength{false}, correctNumber{false}, correctUpper{false}, correctLower{false};
  139. std::cout << "Enter your password: ";
  140. std::cin >> newPassword;
  141. if (newPassword.length() >= 6) {
  142. correctLength = true;
  143. }
  144. for (countingChar i{0}; i < newPassword.length(); i++) {
  145. if (isdigit(newPassword[i])) {
  146. correctNumber = true;
  147. }
  148. if (isupper(newPassword[i])) {
  149. correctUpper = true;
  150. }
  151. if (islower(newPassword[i])) {
  152. correctLower = true;
  153. }
  154. }
  155. if (correctLength && correctNumber && correctLower && correctUpper) {
  156. std::cout << "Thank you. Please use your new password then ext time you log into our system.";
  157. }
  158. else {
  159. std::cout << "We are sorry. Your password does not meet our requirements: " << std::endl;
  160. if (correctLength == false) {
  161. std::cout << " * The password should be at least 6 characters long." << std::endl;
  162. }
  163. if (correctLower == false || correctUpper == false) {
  164. std::cout << " * The password should have at least one upper and one lower case letter." << std::endl;
  165. }
  166. if (correctNumber == false) {
  167. std::cout << " * The password does not contain at least one digit" << std::endl;
  168. }
  169. passwordIsWrong(autoPassword);
  170. }
  171. }
  172.  
  173. void passwordIsWrong(generatedPassword automatedPassword){
  174. std::cout << "Your password was not changed. It remains: " << automatedPassword;
  175. std::cout << "nAs a reminder, your password shouldn" <<
  176. " * Be at least 6 characters longn" <<
  177. " * Contain at least one lower and uppercase lettern" <<
  178. " * Contain at least one digitn" <<
  179. "It is recommended that you change your password the next time you log into our system";
  180. }
  181.  
  182. int main() {
  183. passwordDirections();
  184. userInput name = userEnterName();
  185. countingChar charCount = name.size();
  186. generatedPassword autoPassword = autoGeneratedPassword(reverseName(noPunctuation(noSpaceInName(changeCharCase(inputNameLessThan6(name))))), charCount);
  187. changingPassword(autoPassword);
  188. return EXIT_SUCCESS;
  189. }
Add Comment
Please, Sign In to add comment