int main() { int i = 0; while (i < 3) { char chUser[15]; //abc char chPwd[15]; //123456 int key = 0; //45 0x2d printf("username:\r\n"); scanf("%15s", chUser); printf("password:\r\n"); scanf("%15s", chPwd); //通过crc判断输入的用户名密码是否正确 key = createkey(chUser, chPwd); unsigned char *pkey = (unsigned char *)&key; if (GetCrc(pkey, sizeof(key)) == CrcValue) { puts("OK!"); break; } else { puts("error!"); } i++; } return 0; }
int main (int argc, char *argv[]) { dki_t *data = NULL; dki_t *dkp; int c; int opt_index; int action; const char *file; const char *defconfname = NULL; char *p; char str[254+1]; const char *keyname = NULL; int searchtag; zconf_t *config; progname = *argv; if ( (p = strrchr (progname, '/')) ) progname = ++p; view = getnameappendix (progname, "dnssec-zkt"); defconfname = getdefconfname (view); config = loadconfig ("", (zconf_t *)NULL); /* load built in config */ if ( fileexist (defconfname) ) /* load default config file */ config = loadconfig (defconfname, config); if ( config == NULL ) fatal ("Out of memory\n"); setglobalflags (config); opterr = 0; opt_index = 0; action = 0; #if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG while ( (c = getopt_long (argc, argv, short_options, long_options, &opt_index)) != -1 ) #else while ( (c = getopt (argc, argv, short_options)) != -1 ) #endif { switch ( c ) { case '9': /* ksk rollover help */ ksk_roll ("help", c - '0', NULL, NULL); exit (1); case '1': /* ksk rollover: create new key */ case '2': /* ksk rollover: publish DS */ case '3': /* ksk rollover: delete old key */ case '0': /* ksk rollover: show current status */ action = c; if ( !optarg ) usage ("ksk rollover requires an domain argument", config); kskdomain = domain_canonicdup (optarg); break; case 'h': case 'K': case 'Z': action = c; break; case 'C': pathflag = !pathflag; /* fall through */ case 'P': case 'S': case 'A': case 'D': case 'R': case 's': case 19: case 20: if ( (keyname = parsetag (optarg, &searchtag)) != NULL ) keyname = domain_canonicdup (keyname); action = c; break; case 'F': /* set key lifetime */ lifetime = atoi (optarg); action = c; break; case 'V': /* view name */ view = optarg; defconfname = getdefconfname (view); if ( fileexist (defconfname) ) /* load default config file */ config = loadconfig (defconfname, config); if ( config == NULL ) fatal ("Out of memory\n"); setglobalflags (config); break; case 'c': config = loadconfig (optarg, config); setglobalflags (config); checkconfig (config); break; case 'O': /* read option from commandline */ config = loadconfig_fromstr (optarg, config); setglobalflags (config); checkconfig (config); break; case 'd': /* ignore directory arg */ dirflag = 1; break; case 'k': /* ksk only */ zskflag = 0; break; case 'r': /* switch recursive flag */ recflag = !recflag; break; case 'z': /* zsk only */ kskflag = 0; break; case ':': snprintf (str, sizeof(str), "option \"-%c\" requires an argument.\n", optopt); usage (str, config); break; case '?': if ( isprint (optopt) ) snprintf (str, sizeof(str), "Unknown option \"-%c\".\n", optopt); else snprintf (str, sizeof (str), "Unknown option char \\x%x.\n", optopt); usage (str, config); break; default: abort(); } } if ( kskflag == 0 && zskflag == 0 ) kskflag = zskflag = 1; c = optind; do { if ( c >= argc ) /* no args left */ file = config->zonedir; /* use default directory */ else file = argv[c++]; if ( is_directory (file) ) parsedirectory (file, &data); else parsefile (file, &data); } while ( c < argc ); /* for all arguments */ switch ( action ) { case 'h': usage ("", config); case 'C': createkey (keyname, data, config); break; case 'P': case 'S': case 'A': case 'D': if ( (dkp = (dki_t*)zkt_search (data, searchtag, keyname)) == NULL ) fatal ("Key with tag %u not found\n", searchtag); else if ( dkp == (void *) 01 ) fatal ("Key with tag %u found multiple times\n", searchtag); if ( (c = dki_setstatus_preservetime (dkp, action)) != 0 ) fatal ("Couldn't change status of key %u: %d\n", searchtag, c); break; case 19: /* remove (rename) key file */ if ( (dkp = (dki_t *)zkt_search (data, searchtag, keyname)) == NULL ) fatal ("Key with tag %u not found\n", searchtag); else if ( dkp == (void *) 01 ) fatal ("Key with tag %u found multiple times\n", searchtag); dki_remove (dkp); break; case 20: /* destroy the key (remove the files!) */ if ( (dkp = (dki_t *)zkt_search (data, searchtag, keyname)) == NULL ) fatal ("Key with tag %u not found\n", searchtag); else if ( dkp == (void *) 01 ) fatal ("Key with tag %u found multiple times\n", searchtag); dki_destroy (dkp); break; case 'R': if ( (dkp = (dki_t *)zkt_search (data, searchtag, keyname)) == NULL ) fatal ("Key with tag %u not found\n", searchtag); else if ( dkp == (void *) 01 ) fatal ("Key with tag %u found multiple times\n", searchtag); if ( (c = dki_setstatus (dkp, action)) != 0 ) fatal ("Couldn't change status of key %u: %d\n", searchtag, c); break; case '1': /* ksk rollover new key */ case '2': /* ksk rollover publish DS */ case '3': /* ksk rollover delete old key */ case '0': /* ksk rollover status */ ksk_roll (kskdomain, action - '0', data, config); break; case 'F': zkt_setkeylifetime (data); /* fall through */ default: zkt_list_keys (data); } return 0; }