X-Git-Url: https://iam.tj/gitweb/gitweb.cgi?p=cfe_generate_password.git;a=blobdiff_plain;f=cfe_generate_password.c;h=8746cd1e5f98bd19cdd8c0f0f107b1850d812038;hp=0fe82738208b7777353218d17075d3fbb86c5288;hb=4d52cf071f1865a44f4ae8ad3cd9e58cef7a9dd7;hpb=b21a7e3ffc385e4abbae43f70833a69ebc6784bb diff --git a/cfe_generate_password.c b/cfe_generate_password.c index 0fe8273..8746cd1 100644 --- a/cfe_generate_password.c +++ b/cfe_generate_password.c @@ -60,11 +60,12 @@ #include #include -static const float VERSION = 1.0f; +static const float VERSION = 1.1f; static const size_t TIMESTAMP_SIZE = 6; static const size_t SEED_SIZE = 12; static const size_t PASSWORD_SIZE = 8; static const size_t MESSAGE_SIZE = 128; +static const size_t MAC_ADDR_SIZE = 17; static void pr_usage() @@ -114,7 +115,7 @@ static unsigned int generate_seed(char *mac, char *timestamp, char *seed) { unsigned int result = 0; - if (mac && strlen(mac) == 17) { + if (mac && strlen(mac) == MAC_ADDR_SIZE) { size_t i; char *mac_ptr = mac + 9; size_t ts_len = strlen(timestamp); @@ -140,7 +141,7 @@ generate_pass(char *seed, char *password) { unsigned int result = 0; - if (seed && strlen(seed) == 12) { + if (seed && strlen(seed) == SEED_SIZE) { unsigned int timestamp, byte, key, pass; timestamp = byte = 0; if(! sscanf(seed, "%06x", ×tamp)) @@ -230,7 +231,8 @@ main(int argc, char **argv, char **env) if (! generate_pass(seed, password)) pr_error_exit(0, "unable to generate password"); - printf("MAC address: %s Timestamp: %s Seed: %s Password: %s\n", MAC_ADDR, timestamp, seed, password); + if (opt_seed || opt_pass) + printf("MAC address: %s Timestamp: %s Seed: %s Password: %s\n", MAC_ADDR, timestamp, seed, password); } return result;