Skip to content

Instantly share code, notes, and snippets.

Created February 13, 2012 18:51
Show Gist options
  • Save anonymous/1819034 to your computer and use it in GitHub Desktop.
Save anonymous/1819034 to your computer and use it in GitHub Desktop.
Authentication
#include <stdio.h>
#include <string.h>
int auth(){
int auth = 0;
FILE* fp = fopen("passwd.txt", "r");
char exp_user[10];
char exp_pass[10];
fscanf(fp, "%s %s", exp_user, exp_pass);
// Get user input
printf("Username: ");
char user[10];
scanf("%s", user);
printf("Password: ");
char pass[10];
scanf("%s", pass);
if (!strcmp(user, exp_user) && !strcmp(pass, exp_pass)){
auth = 1;
}
return auth;
}
int main(){
if (auth()){
printf("User validated");
} else {
printf("Invalid user");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment