C/C++ Automatic Password Generator
This code can generate a unique password as your desired lengeth. Example if you want 12 letters unique set of password than this code can make it for you!
code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h> // ASR
void generate_password(int length) {
char characters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*(){}?<>,';:/\\";
char password[100]; // Fixed size array to avoid dynamic allocation issues in Turbo C++
int i;
srand(time(0));
for (i = 0; i < length; i++) {
int randomIndex = rand() % (sizeof(characters) - 1);
password[i] = characters[randomIndex];
}
password[length] = '\0';
printf("Generated Password: %s\n", password);
}
int main() {
int length;
printf("Enter the length of the password: ");
scanf("%d", &length);
if (length > 99) {
printf("Length too long! Please enter a length less than 100.\n");
return 1;
}
generate_password(length);
return 0;
// By Adeshjeet Singh
}
No comments:
Post a Comment