Skip to content

Instantly share code, notes, and snippets.

@typelogic
Created February 9, 2019 16:21
Show Gist options
  • Save typelogic/c9078b6358d69926d41b42bc8953de9f to your computer and use it in GitHub Desktop.
Save typelogic/c9078b6358d69926d41b42bc8953de9f to your computer and use it in GitHub Desktop.
snippet: crypt
//#define _XOPEN_SOURCE
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <unistd.h>
#include <crypt.h>
int main(int argc, char *argv[]) {
if ( argc < 3 || (int) strlen(argv[2]) > 16 ) {
printf("usage: %s password salt\n", argv[0]);
printf("--salt must not larger than 16 characters\n");
return 1;
}
char salt[21];
sprintf(salt, "$6$%s$", argv[2]);
printf("%s\n", crypt((char*) argv[1], (char*) salt));
//printf("%s\n", crypt_r((char*) argv[1], (char*) salt));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment