The code shown below is for a program that generates a random password. The password char makeup itself is fine, but the issue comes with the password length. It is supposed to be a random number between 12 and 20(upper and lower). However it always sets to 1 value per device. I'm aware that this is a seeding issue but I do not know what seed to use. If anyone has suggestions, please comment them below.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int lower = 12, upper = 20, count = 1;
int i;
for (i = 0; i < count; i++) {
int num = (rand() %
(upper - lower + 1)) + lower;
int N = ("%d", num);
**srand(time(0));**
randomPasswordGeneration(N);
return 0;
}
}
void randomPasswordGeneration(int N)
{
int i = 0;
int randomizer = 0;
char numbers[] = "0123456789";
char letter[] = "abcdefghijklmnoqprstuvwyzx";
char LETTER[] = "ABCDEFGHIJKLMNOQPRSTUYWVZX";
char symbols[] = "!@#$^&*? -_/";
char password[N];
randomizer = rand() % 4;
for (i = 0; i < N; i++) {
if (randomizer == 1) {
password[i] = numbers[rand() % 10];
randomizer = rand() % 4;
printf("%c", password[i]);
}
else if (randomizer == 2) {
password[i] = symbols[rand() % 8];
randomizer = rand() % 4;
printf("%c", password[i]);
}
else if (randomizer == 3) {
password[i] = LETTER[rand() % 26];
randomizer = rand() % 4;
printf("%c", password[i]);
}
else {
password[i] = letter[rand() % 26];
randomizer = rand() % 4;
printf("%c", password[i]);
}
}
}