Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 70 lines (60 sloc) 1.444 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

#include "pfile.h"

FILE* open_login_file(char *nom_fichier){
FILE *login_file = fopen(nom_fichier, "r");
return login_file;
}

int close_login_file(FILE* login_file){
return fclose(login_file);
}

int check_authentification(char *username, char* pwd, FILE *fichier){

char *founded_username = NULL;
char temp[LENG_STRING]="";
if (fichier!=NULL){
while(fgets(temp, LENG_STRING, fichier)){
char user_temp[LENG_STRING]="";
// récupération du nom de l'utilisateur (extraction de la premiere partie de la chaine : avant le ':')
int i=0;
for (i ; i < strlen(temp); i++){

if (temp[i]==58){ // ":"
//printf("username : %s\n", user_temp);
break;
}
else{
user_temp[i]=temp[i];
}
}
if (user_temp!=""){ //comparaison du nom de l'utilisateur
if (strcmp(user_temp, username)==0){
//printf("username %s OK\n", username);
if(check_pwd(pwd, strstr(temp, ":")+1)){
return 1;
}
else{
return 0;
}
}
}
}
}
return 0;
}

int check_pwd(char* pwd, char* chaine){
// vérification du mot de passe
if(strncmp(chaine, pwd, strlen(pwd))==0){
//printf("PWD %s OK\n", pwd);
return 1;
}
return 0;
}



int main (int argc, char const *argv[])
{
FILE* testf = open_login_file("README");
if(check_authentification("admin", "strong_pwd", testf)){
close_login_file(testf);
printf("ok\n");
return 0;
}
else{
printf("not ok\n");
}
}
Something went wrong with that request. Please try again.