diff options
author | Joursoir <chat@joursoir.net> | 2021-01-14 19:32:05 +0000 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2021-01-14 19:32:05 +0000 |
commit | 96b8793a09ccc9f8fa92444d540d77d037475dfe (patch) | |
tree | 901fb81491de6ed72b6c3faa504dc7c8f34f6f68 /src/implementation.c | |
parent | 3165436ed14cb353843abf01e9208c088583bc40 (diff) | |
download | lock-password-96b8793a09ccc9f8fa92444d540d77d037475dfe.tar.gz lock-password-96b8793a09ccc9f8fa92444d540d77d037475dfe.tar.bz2 lock-password-96b8793a09ccc9f8fa92444d540d77d037475dfe.zip |
refactor generator of password
Diffstat (limited to 'src/implementation.c')
-rw-r--r-- | src/implementation.c | 26 |
1 files changed, 6 insertions, 20 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; |