Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <ctime>
- using namespace std;
- /*
- You're challenge for today is to create a random password generator!
- For extra credit, allow the user to specify the amount of passwords to generate.
- For even more extra credit, allow the user to specify the length of the strings he wants to generate!
- */
- int main()
- {
- srand( time(NULL) );
- char CHA;
- int LENGTH = 0, AMOUNT = 0, NUMBERS = 0, LETTERS = 0, CAPITALS = 0, SPECIAL = 0, RAND1 = 0, RAND2 = 0;
- bool numbers = false, letters = false, capitals = false, special = false;
- string STRINGLET = "abcdefghijklmnopqrstuvwxyzzflkjda"; //31
- string STRINGCAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZSRTKLJD"; //31
- string STRINGNUM = "012345678901234567890123456789016"; //31
- string STRINGSPE = "`~!@#$%^&*()_+-={}[]|\\:\";'<>?,./"; //31
- cout << "Lenght of password in positive whole numbers? (Maximum 50 characters): ";
- cin >> LENGTH;
- cout << "\nHow many passwords of " << LENGTH << " characters would you like to generate? ";
- cin >> AMOUNT;
- if( LENGTH > 0 && LENGTH < 51 && AMOUNT > 0 )
- {
- cout << "\nWould you like to include letters in your password? (Y/N): ";
- cin >> CHA;
- if( CHA == 'y' || CHA == 'Y' )
- {
- letters = true;
- }
- cout << "\nWould you like to include CAPITAL letters in your password? (Y/N): ";
- cin >> CHA;
- if( CHA == 'y' || CHA == 'Y' )
- {
- capitals = true;
- }
- cout << "\nWould you like to include numbers in your password? (Y/N): ";
- cin >> CHA;
- if( CHA == 'y' || CHA == 'Y' )
- {
- numbers = true;
- }
- cout << "\nWould you like to include special characters in your password? (Y/N): ";
- cin >> CHA;
- if( CHA == 'y' || CHA == 'Y' )
- {
- special = true;
- }
- if( letters == false && numbers == false && capitals == false && special == false )
- {
- cout << "You haven't selected any characters for your passwords to be generated from.\nProgram terminated.\n";
- cin.get();
- cin.get();
- return 1;
- }
- cout << "\n\nPasswords:\n\n";
- for( int X = 0; X != AMOUNT; X++ )
- {
- for( int Y = 0; Y != LENGTH; Y++ )
- {
- if( letters == true && numbers == false && special == false && capitals == false )
- {
- RAND2 = rand() % 31 + 0;
- cout << STRINGLET[RAND2];
- }
- if( numbers == true && letters == false && capitals == false && special == false )
- {
- RAND2 = rand() % 31 + 0;
- cout << STRINGNUM[RAND2];
- }
- if( capitals == true && numbers == false && letters == false && special == false )
- {
- RAND2 = rand() % 31 + 0;
- cout << STRINGCAP[RAND2];
- }
- if( special == true && capitals == false && numbers == false && letters == false )
- {
- RAND2 = rand() % 31 + 0;
- cout << STRINGSPE[RAND2];
- }
- if( letters == true && capitals == true && numbers == false && special == false )
- {
- RAND1 = rand() % 2 + 1;
- RAND2 = rand() % 31 + 0;
- if ( RAND1 == 1 )
- {
- cout << STRINGLET[RAND2];
- }
- if ( RAND1 == 2 )
- {
- cout << STRINGCAP[RAND2];
- }
- }
- if( letters == true && numbers == true && capitals == false && special == false )
- {
- RAND1 = rand() % 2 + 1;
- RAND2 = rand() % 31 + 0;
- if ( RAND1 == 1 )
- {
- cout << STRINGLET[RAND2];
- }
- if ( RAND1 == 2 )
- {
- cout << STRINGNUM[RAND2];
- }
- }
- if( letters == true && special == true && numbers == false && capitals == false )
- {
- RAND1 = rand() % 2 + 1;
- RAND2 = rand() % 31 + 0;
- if ( RAND1 == 1 )
- {
- cout << STRINGLET[RAND2];
- }
- if ( RAND1 == 2 )
- {
- cout << STRINGSPE[RAND2];
- }
- }
- if( capitals == true && special == true && numbers == false && letters == false )
- {
- RAND1 = rand() % 2 + 1;
- RAND2 = rand() % 31 + 0;
- if ( RAND1 == 1 )
- {
- cout << STRINGCAP[RAND2];
- }
- if ( RAND1 == 2 )
- {
- cout << STRINGSPE[RAND2];
- }
- }
- if( numbers == true && capitals == true && letters == false && special == false )
- {
- RAND1 = rand() % 2 + 1;
- RAND2 = rand() % 31 + 0;
- if ( RAND1 == 1 )
- {
- cout << STRINGCAP[RAND2];
- }
- if ( RAND1 == 2 )
- {
- cout << STRINGNUM[RAND2];
- }
- }
- if( special == true && numbers == true && capitals == false && letters == false )
- {
- RAND1 = rand() % 2 + 1;
- RAND2 = rand() % 31 + 0;
- if ( RAND1 == 1 )
- {
- cout << STRINGNUM[RAND2];
- }
- if ( RAND1 == 2 )
- {
- cout << STRINGSPE[RAND2];
- }
- }
- if( letters == true && capitals == true && numbers == true && special == false )
- {
- RAND1 = rand() % 3 + 1;
- RAND2 = rand() % 31 + 0;
- if ( RAND1 == 1 )
- {
- cout << STRINGLET[RAND2];
- }
- if ( RAND1 == 2 )
- {
- cout << STRINGCAP[RAND2];
- }
- if ( RAND1 == 3 )
- {
- cout << STRINGNUM[RAND2];
- }
- }
- if( letters == true && capitals == true && special == true && numbers == false )
- {
- RAND1 = rand() % 3 + 1;
- RAND2 = rand() % 31 + 0;
- if ( RAND1 == 1 )
- {
- cout << STRINGLET[RAND2];
- }
- if ( RAND1 == 2 )
- {
- cout << STRINGCAP[RAND2];
- }
- if ( RAND1 == 3 )
- {
- cout << STRINGSPE[RAND2];
- }
- }
- if( letters == true && numbers == true && special == true && capitals == false )
- {
- RAND1 = rand() % 3 + 1;
- RAND2 = rand() % 31 + 0;
- if ( RAND1 == 1 )
- {
- cout << STRINGLET[RAND2];
- }
- if ( RAND1 == 2 )
- {
- cout << STRINGNUM[RAND2];
- }
- if ( RAND1 == 3 )
- {
- cout << STRINGSPE[RAND2];
- }
- }
- if( numbers == true && capitals == true && special == true && letters == false )
- {
- RAND1 = rand() % 4 + 2;
- RAND2 = rand() % 31 + 0;
- if ( RAND1 == 2 )
- {
- cout << STRINGCAP[RAND2];
- }
- if ( RAND1 == 3 )
- {
- cout << STRINGNUM[RAND2];
- }
- if ( RAND1 == 4 )
- {
- cout << STRINGSPE[RAND2];
- }
- }
- if( letters == true && capitals == true && numbers == true && special == true )
- {
- RAND1 = rand() % 4 + 1;
- RAND2 = rand() % 31 + 0;
- if ( RAND1 == 1 )
- {
- cout << STRINGLET[RAND2];
- }
- if ( RAND1 == 2 )
- {
- cout << STRINGCAP[RAND2];
- }
- if ( RAND1 == 3 )
- {
- cout << STRINGNUM[RAND2];
- }
- if ( RAND1 == 4 )
- {
- cout << STRINGSPE[RAND2];
- }
- }
- }
- cout << "\n";
- }
- }
- else
- {
- cout << "You've entered an incorrect number for the length or amount, the program will now end." << endl;
- }
- cout << "\n\nDone.\n\nPress Enter to Quit!";
- cin.get();
- cin.get();
- return 0;
- }
Add Comment
Please, Sign In to add comment