# Check if a string match a (bcrypt) hash 2023-05-04T16:55:17Z ``` /* * Description: Check if a hash match a string * Version: 0.1 * Licence: MIT * Author: Xavier Cartron prx@si3t.ch */ #include #include #include #include #include #include /* 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 ", 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; } ```