From d2d892202909414cf7a4b4e6bf90f519323c1efb Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Mon, 13 Mar 2023 11:44:01 +0700 Subject: [PATCH] readme file and help message added --- README.md | 10 ++++++++++ src/main.c | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..510042d --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# PASSWORD GENERATOR + +```sh +pwdgen -h + pwdgen - generates a password of the given size from the standard alphabet + pwdgen - generates four characters from the given alphabet + pwdgen - generates a password of the given length from the given alphabet + pwdgen - generates a four character password from the standard alphabet + +``` \ No newline at end of file diff --git a/src/main.c b/src/main.c index 7f6ae41..7d8e0a5 100644 --- a/src/main.c +++ b/src/main.c @@ -9,6 +9,10 @@ #include #define ALPHABET "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM[]{}<>()*#" +#define HELP_MESSAGE "\tpwdgen - generates a password of the given size from the standard alphabet\n"\ + "\tpwdgen - generates four characters from the given alphabet\n"\ + "\tpwdgen - generates a password of the given length from the given alphabet\n"\ + "\tpwdgen - generates a four character password from the standard alphabet\n" char *get_random_string(const char *alphabet, int quantity) { // printf("%s\n%ld\n", alphabet, strlen(alphabet)); @@ -47,7 +51,10 @@ char *get_random_string(const char *alphabet, int quantity) { int main(int argc, char *argv[]) { if (argc == 2) { - if (atoi(argv[1]) > 0) { + if (!strcmp(argv[1], "-h")) { + printf("%s\n", HELP_MESSAGE); + return 0; + } else if (atoi(argv[1]) > 0) { int quantity = atoi(argv[1]); char *pwd = get_random_string(ALPHABET, quantity); printf("Password -> %s\n", pwd); @@ -80,6 +87,7 @@ int main(int argc, char *argv[]) { // printf("%s\n", get_file_extension(argv[1])); char *pwd = get_random_string(argv[1], 4); printf("Password -> %s\n", pwd); + return 0; } } if (argc == 3) { @@ -87,9 +95,10 @@ int main(int argc, char *argv[]) { char *alphabet = argv[1]; char *pwd = get_random_string(alphabet, quantity); printf("Password -> %s\n", pwd); + return 0; } - // char *pwd = get_random_string(ALPHABET, 4); - // printf("Password -> %s\n", pwd); + char *pwd = get_random_string(ALPHABET, 4); + printf("Password -> %s\n", pwd); return 0; }