Check if a string match a (bcrypt) hash
/*
* Description: Check if a hash match a string
* Version: 0.1
* Licence: MIT
* Author: Xavier Cartron prx@si3t.ch
*/
#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <pwd.h>
#include <unistd.h>
/* compare password passed on stdin with hash passed as argv[2] */
int
main(int argc, char *argv[])
{
char pw[LINE_MAX] = {'\0'};
if (argc != 2)
errx(1, "usage: printf \"pw\" | %s <hash>", argv[0]);
if (fgets(pw, LINE_MAX, stdin) == NULL)
err(1, "fail to read from stdin");
pw[strcspn(pw, "\n")] = '\0'; /* remove ending \n if any */
if (crypt_checkpass(pw, argv[1]) != 0)
return 1;
printf("match \\o/\n");
return 0;
}