/* compile with -lcrypt */ #include #include #include #define _XOPEN_SOURCE #include char *crypt(const char *key, const char *salt); #define SECRETFILE "/home/tentti/.salaisuus" char salt[] = "kR"; int main(void) { char password[32]; char encryptedpw[] = "kRgzA/gPPPf0Q"; char secret[30]; char *hash; int authenticated = 0; FILE *f; printf("Password: "); scanf("%s", password); hash = crypt(password, salt); authenticated |= !(strcmp(hash, encryptedpw)); if (authenticated) { if (!(f=fopen(SECRETFILE,"r"))) { perror("fopen()"); exit(1); } fgets(secret, sizeof(secret), f); fclose(f); printf("secret is '%s'\n", secret); } else { printf("wrong password, sorry\n"); } exit(0); }