aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/implementation.c26
-rw-r--r--src/implementation.h2
-rw-r--r--src/main.c4
3 files changed, 9 insertions, 23 deletions
diff --git a/src/implementation.c b/src/implementation.c
index 7d19282..d2f71ea 100644
--- a/src/implementation.c
+++ b/src/implementation.c
@@ -205,28 +205,14 @@ int userEnterPassword(int minlen, int maxlen, char *path_insert, int flag_echo,
return rvalue;
}
-char *generatePassword(char *dest, int amount, int max_len)
+char *generatePassword(char *dest, int amount)
{
- char allowed_symbols[] = {
- 'A','E','I','J','O','U','B','C','D','F','G','H',
- 'K','L','M','N','P','Q','R','S','T','V','W','X',
- 'Y','Z','a','e','i','j','o','u','b','c','d','f',
- 'g','h','k','l','m','n','p','q','r','s','t','v',
- 'w','x','y','z','1','2','3','4','5','6','7','8',
- '9','0','!','#','$',';','%','^',':','&','?','*',
- '(',')','-','_','+','=','<', '>'
- };
- int max = sizeof(allowed_symbols);
- srand(time(NULL));
-
- char password[max_len];
- for(int i=0; i < amount; i++)
- {
- char c = allowed_symbols[rand() % max];
+ int i, min = 33, max = 126;
+ char password[amount];
- password[i] = c;
- password[i+1] = '\0';
- }
+ srand(time(NULL));
+ for(i = 0; i < amount; i++)
+ password[i] = min + rand() % (max-min);
strcpy(dest, password);
return dest;
diff --git a/src/implementation.h b/src/implementation.h
index f41cc4a..ba436a7 100644
--- a/src/implementation.h
+++ b/src/implementation.h
@@ -10,7 +10,7 @@ void nonvisibleEnter(int status);
void insertPass(char *add_path, char *password, int flag_copy);
char *typePass(char *text, char *dest, int minlen, int maxlen);
int userEnterPassword(int minlen, int maxlen, char *path_insert, int flag_echo, int flag_copy);
-char *generatePassword(char *dest, int amount, int max_len);
+char *generatePassword(char *dest, int amount);
unsigned long hash(char *str);
int getOverwriteAnswer(char *path);
diff --git a/src/main.c b/src/main.c
index fd1345b..8639597 100644
--- a/src/main.c
+++ b/src/main.c
@@ -293,8 +293,8 @@ static void cmd_generate(int argc, char *argv[])
}
// generate password
- char gpass[MAXLEN_PASSWORD];
- generatePassword(gpass, pass_length, MAXLEN_PASSWORD);
+ char gpass[pass_length];
+ generatePassword(gpass, pass_length);
insertPass(path_to_password, gpass, flag_copy);
if(!flag_copy) printf("Generated password: %s\n", gpass);