Skip to content

Instantly share code, notes, and snippets.

@simon-engledew
Last active September 4, 2020 15:19
Show Gist options
  • Save simon-engledew/a9d9ec1f8058e0a79eb72ddea0d6bed8 to your computer and use it in GitHub Desktop.
Save simon-engledew/a9d9ec1f8058e0a79eb72ddea0d6bed8 to your computer and use it in GitHub Desktop.
tiny random password generator
#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]);
}
}
pwgen: main.c
gcc -lsodium -o $@ $<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment