Last active
September 4, 2020 15:19
-
-
Save simon-engledew/a9d9ec1f8058e0a79eb72ddea0d6bed8 to your computer and use it in GitHub Desktop.
tiny random password generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "sodium.h" | |
#include <stdlib.h> | |
#include <errno.h> | |
#define ENCODING "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" | |
int main(int argc, char** argv) { | |
if (argc != 2) { | |
fprintf(stderr, "usage: %s <count>", argv[0]); | |
return 1; | |
} | |
long chars = strtol(argv[1], NULL, 10); | |
if (errno != 0) { | |
fprintf(stderr, "usage: %s <count>", argv[0]); | |
return 1; | |
} | |
uint32_t index; | |
for (short n = 0; n < chars; n++) { | |
index = randombytes_uniform((sizeof ENCODING) - 1); | |
printf("%c", ENCODING[index]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pwgen: main.c | |
gcc -lsodium -o $@ $< |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment