This C program generates N number of passwords, each of length M. This problem focuses on finding the N permutations each of length M.
Here is the source code of the C program to generate random passwords of equal length. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
/* Length of the password */
int length;
int num;
int temp;
printf("Enter the length of the password: ");
scanf("%d", &length);
printf("\nEnter the number of passwords you want: ");
scanf("%d", &num);
/* Seed number for rand() */
srand((unsigned int) time(0) + getpid());
while(num--)
{
temp = length;
printf("\n");
while(temp--) {
putchar(rand() % 56 + 65);
srand(rand());
}
temp = length;
}
printf("\n");
return EXIT_SUCCESS;
}
$ gcc password.c -o password $ ./password Enter the length of the password: 8 Enter the number of passwords you want: 5 Yfqdpshp GZJqGuiB ^jFUTLOo WbNK]Teu ]wrQSBNY
Sanfoundry Global Education & Learning Series – 1000 C Programs.
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data Structures and Algorithms.
Related Posts:
- Apply for C Internship
- Apply for Computer Science Internship
- Watch Advanced C Programming Videos
- Check C Books
- Practice Computer Science MCQs