This scripts purpose is to randomly generate a password for you, but you set the length limit of the password.
Code:
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
/*
* General purpose of this program is to generate a password for you.
* Created by ZionHD
* Copyright (c) 2015 Console-Forums
*/
using namespace std;
char genChar(); // Selects a random character from array
int main()
{
srand(time(0));
int length;
// Asks user for the length of which they want there password
cout << "Length of password: ";
cin >> length;
// For loop, keeps looping until i = length of password user wants.
for (int i = 0; i < length; i++)
{
cout << genChar(); // Displays character that is randomly selected.
}
// Alerts the user that the password was generated!
cout << "\nYour password has been generated!" << endl;
return 0;
}
char genChar()
{
// Array of characters to use
const char pass[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
// Gets the size of variable pass
int length = sizeof(pass) - 1;
return pass[rand() % length];
}