I have made a random password generator.In function void passwordGenerator(int sizeOfPassword)
The problem here is this I am trying to save the password generated by the program in sum
but I don't know how to do it properly.
How do I save random digits password in sum
.
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
void passwordGenerator(int sizeOfPassword)
{
srand(time(NULL));
char allChars[] = {"0123456789!@#$%^&*abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
char sum;
for(int i = 0; i < sizeOfPassword; i++){
sum = sum + allChars[rand()%sizeOfPassword];
}
std::cout<<sum<<std::endl;
}
int main()
{
int sizeOutput;
char wannaPlay = 'y';
while(wannaPlay == 'y'){
std::cout<<"Enter the size of password: ";
std::cin>>sizeOutput;
passwordGenerator(sizeOutput);
std::cout<<"\nRun Again[y/n]? : ";
std::cin>>wannaPlay;
}
return 0;
}
Thank you
Aucun commentaire:
Enregistrer un commentaire