micro-utils/src/cryptpw.c
2024-07-31 13:58:31 +03:00

36 lines
610 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static char *gen_salt(void) {
srand(getpid());
static char salt[15];
char abc[] = "asdfghjklzxcvbnmqwertyuiop1234567890";
size_t i = 0;
for (; i < sizeof(salt); i++)
salt[i] = abc[rand() % sizeof(abc)];
salt[i] = '\0';
return salt;
}
int main(int argc, char **argv) {
if (argc < 2) {
puts("cryptpw: missing operand\ncryptpw [password] [own salt]");
return 0;
}
char *salt_ptr = gen_salt();
if (argc > 2)
salt_ptr = argv[2];
char *cpass = crypt(argv[1], salt_ptr);
if (cpass == NULL)
return 1;
puts(cpass);
return 0;
}