C Program to Generate N Number of Passwords of Length M Each

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.

  1. #include <time.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main(void)
  6. {
  7.     /* Length of the password */
  8.     int length;
  9.     int num;
  10.     int temp;
  11.     printf("Enter the length of the password: ");
  12.     scanf("%d", &length);
  13.     printf("\nEnter the number of passwords you want: ");
  14.     scanf("%d", &num);
  15.     /* Seed number for rand() */
  16.     srand((unsigned int) time(0) + getpid());
  17.  
  18.     while(num--)
  19.     {
  20.         temp = length;
  21.         printf("\n");
  22.         while(temp--) {
  23.             putchar(rand() % 56 + 65);
  24.             srand(rand());
  25.         }
  26.  
  27.         temp = length;
  28.     }
  29.  
  30.     printf("\n");
  31.  
  32.     return EXIT_SUCCESS;
  33. }

$ 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.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.