Advertisement
FizzyGalacticus

HW9 Part 3

Nov 16th, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. //Dustin Dodson
  2. //Introduction to Digital Forensics
  3. //HW9.cpp
  4.  
  5.  
  6. //Library needed for input/output
  7. #include <iostream>
  8.  
  9. //Library needed for storing std::string variables
  10. #include <string>
  11.  
  12. #include <stdlib.h> //Needed for srand() and rand()
  13. #include <time.h>   //Needed for time()
  14.  
  15. /*Main function can take a std::string through command line
  16. or will prompt for one if none are given            */
  17. int main(const int argc, char * argv[])
  18. {
  19.     //Setting up initial variables
  20.     std::string attemptPass, pass = "";
  21.    
  22.     //Keeping track of time as user types
  23.     time_t startTime = time(NULL), typeTime;
  24.     int runTime = 0;
  25.    
  26.     //Seed for the rand() function
  27.     srand(startTime);
  28.    
  29.     /*If there was a std::string passed through command line
  30.     then set it as given password, otherwise prompt user*/
  31.     if(argc > 1) attemptPass = argv[1];
  32.     else
  33.     {
  34.         std::cout << "Password: ";
  35.         getline(std::cin, attemptPass);
  36.     }
  37.    
  38.     //Store time after user gives password
  39.     typeTime = time(NULL);
  40.    
  41.     /*Find out how many seconds it took user to
  42.     enter password*/
  43.     runTime = (typeTime-startTime);
  44.    
  45.     /*This series of loops will generate a random password
  46.     that has a length of at least 9. The password will vary
  47.     depending on how long it took user to give input.*/
  48.     while(pass.size()<9)
  49.     {
  50.         int random = (rand()%20);
  51.         for(int i = 0; i < random; i++)
  52.         {
  53.             if(i%2==0) pass += char((rand()%52)+65);
  54.             else if(i%3==0) pass += char((runTime%10)+48);
  55.             else pass += char((rand()%15)+33);
  56.         }
  57.     };
  58.    
  59.     //Compare generated password with one given by user, give respective message
  60.     ((attemptPass == pass)?(std::cout<<"You have passed the test!\n"):(std::cout<<"You have failed the test!\n"));
  61.    
  62.     //Prompts for any kind of user input to close window
  63.     char input;
  64.     std::cout << "Press ENTER to continue...";
  65.     std::cin.ignore(80, '\n');
  66.    
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement