DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Password Generator

02.09.2006
| 207 views |
  • submit to reddit
        
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>

int main() {

   int slump;
   int tal;
   int count = 0;
   time_t tid;

   slump = time(&tid);
   printf("Press CTRL-C to abort.\n\n");
   printf("Password: ");

   while (1) {
      srandom(slump);
      slump=random();
      tal= 1 + (int) (250.0*random() / (RAND_MAX+1.0) );
      if (((tal > 47) && (tal < 58)) ||
                         ((tal > 64) && (tal < 91)) ||
                         ((tal > 96) && (tal < 123))) {
         if (count < 8 ) {
            printf("%c", (char) tal);
            count++;
         } else {
            printf("\nPassword generated.");
            getchar();
            printf("\nPassword: ");
            count = 0;
         }
      }
   }
   return(0);
}

    
    Tags:
  • C