Portál AbcLinuxu, 23. dubna 2024 17:15
#include <memory.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <ctype.h> #include <crack.h> void usage(char *command) { char *c, *comm; comm = command; while ((c = strrchr(comm, '/')) != NULL) { comm = c + 1; } fprintf(stderr, "Usage: %s -d dictionary\n\n", comm); fprintf(stderr, " -d dictionary file for cracklib\n\n"); fprintf(stderr, " The password is expected to be given via stdin.\n\n"); exit(-1); } int main(int argc, char **argv) { extern char *optarg; int c; char f[256]; char *dictionary = NULL; char *password; char *reply; while ( (c = getopt(argc, argv, "d:")) != EOF){ switch(c) { case 'd': dictionary = strdup(optarg); break; default: usage(argv[0]); } } if (dictionary == NULL) { fprintf(stderr, "ERR - Wrong Command Line\n\n"); usage(argv[0]); } password = fgets(f, sizeof(f), stdin); if (password == NULL) { fprintf(stderr, "ERR - Failed to read password\n\n"); exit(-2); } reply = FascistCheck(password, dictionary); if (reply != NULL) { fprintf(stderr, "ERR - %s\n\n", reply); exit(-3); }else { int pocet; pocet=0; char *znak; char *dolni="abcdefghijklmnopqrstuvwxyz"; char *horni="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char *cisla="1234567890"; char *special="!@#$%^&*()_+|~"; znak = strpbrk (password, dolni); if (znak != NULL) pocet++; znak = strpbrk (password, horni); if (znak != NULL) pocet++; znak = strpbrk (password, cisla); if (znak != NULL) pocet++; znak = strpbrk (password, special); if (znak != NULL) pocet++; fprintf(stderr, "pocet - %i\n\n", pocet); if (pocet<3) exit(-4); } exit(0); }
Tiskni Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.