This is a simple password generator. What do you think about it? I am learning C for a while at school and at home. This just has a mix of symbols, lowercase, uppercase and numbers, with a configurable length.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int i = 0;
int n = 0;
int randomizer = 0;
srand((unsigned int)(time(NULL)));
char numbers [] = "1234567890";
char letter [] = "abcdefghijklmnoqprstuvwyzx";
char letterr [] = "ABCDEFGHIJKLMNOQPRSTUYWVZX";
char symbols [] = "!@#$%^&*(){}[]:<>?,./";
printf("\nHow long password:");
scanf("%d", &n);
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() % 26];
randomizer = rand() % 4;
printf("%c", password[i]);
}
else if (randomizer == 3)
{
password[i] = letterr[rand() % 26];
randomizer = rand() % 4;
printf("%c", password[i]);
}
else
{
password[i] = letter[rand() % 21];
randomizer = rand() % 4;
printf("%c", password[i]);
}
}
return main();
}
rand()
is weak, predictable, and reversible on most platforms. \$\endgroup\$letterr
for capital letters seems lazy \$\endgroup\$"1234567890abc…xyzABC…XYZ!@#$%^&*(){}[]:<>?,./"
, and most of the other code will collapse into one small loop. — Or better yet, assuming ASCII, just pick a random integer between 33 and 126 and use that as the character and you don't even need a list of characters. \$\endgroup\$