Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Dustin Dodson
- //Introduction to Digital Forensics
- //HW9.cpp
- //Library needed for input/output
- #include <iostream>
- //Library needed for storing std::string variables
- #include <string>
- #include <stdlib.h> //Needed for srand() and rand()
- #include <time.h> //Needed for time()
- /*Main function can take a std::string through command line
- or will prompt for one if none are given */
- int main(const int argc, char * argv[])
- {
- //Setting up initial variables
- std::string attemptPass, pass = "";
- //Keeping track of time as user types
- time_t startTime = time(NULL), typeTime;
- int runTime = 0;
- //Seed for the rand() function
- srand(startTime);
- /*If there was a std::string passed through command line
- then set it as given password, otherwise prompt user*/
- if(argc > 1) attemptPass = argv[1];
- else
- {
- std::cout << "Password: ";
- getline(std::cin, attemptPass);
- }
- //Store time after user gives password
- typeTime = time(NULL);
- /*Find out how many seconds it took user to
- enter password*/
- runTime = (typeTime-startTime);
- /*This series of loops will generate a random password
- that has a length of at least 9. The password will vary
- depending on how long it took user to give input.*/
- while(pass.size()<9)
- {
- int random = (rand()%20);
- for(int i = 0; i < random; i++)
- {
- if(i%2==0) pass += char((rand()%52)+65);
- else if(i%3==0) pass += char((runTime%10)+48);
- else pass += char((rand()%15)+33);
- }
- };
- //Compare generated password with one given by user, give respective message
- ((attemptPass == pass)?(std::cout<<"You have passed the test!\n"):(std::cout<<"You have failed the test!\n"));
- //Prompts for any kind of user input to close window
- char input;
- std::cout << "Press ENTER to continue...";
- std::cin.ignore(80, '\n');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement