#include <iostream>
#include <ctime>
#include <cmath>
#include <cctype>
using namespace std;
void random();
char thin, chin;
char pass[36] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
int num, z, time1, r;
int main() {
cout << "This is the random password generator. How many characters do you want the password to be?" << endl;
cin >> time1;
cout << endl;
random();
cout << endl;
cout << endl;
system("PAUSE");
return 0;
}
void random() {
srand(time(NULL));
while (time1 > 0) {
time1--;
z = rand() % 36 + 1;
chin = pass[z];
if (pass[z] == 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z') {
r = rand() % 2;
if (r == 1) { //convert to upper
thin = toupper(chin);
cout << thin;
}
else cout << chin; //display letter uncapped
}
else cout << chin; //display number
}
}
for some reason, when i run this, spaces appear in the password. how do i fix this?
example:
2H43fdas fjdkas3423hjh4h23GHJFS65 fjdksa
what is want is
2H43fdasfjdkas3423hjh4h23GHJFS65fjdksa
#include <ctime>
#include <cmath>
#include <cctype>
using namespace std;
void random();
char thin, chin;
char pass[36] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
int num, z, time1, r;
int main() {
cout << "This is the random password generator. How many characters do you want the password to be?" << endl;
cin >> time1;
cout << endl;
random();
cout << endl;
cout << endl;
system("PAUSE");
return 0;
}
void random() {
srand(time(NULL));
while (time1 > 0) {
time1--;
z = rand() % 36 + 1;
chin = pass[z];
if (pass[z] == 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z') {
r = rand() % 2;
if (r == 1) { //convert to upper
thin = toupper(chin);
cout << thin;
}
else cout << chin; //display letter uncapped
}
else cout << chin; //display number
}
}
for some reason, when i run this, spaces appear in the password. how do i fix this?
example:
2H43fdas fjdkas3423hjh4h23GHJFS65 fjdksa
what is want is
2H43fdasfjdkas3423hjh4h23GHJFS65fjdksa