Guest User

Untitled

a guest
Oct 13th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | None | 0 0
  1. int autenticazione(char *user, char *pass){// funzione da rivedere
  2.     int ris=0;
  3.     char temp[MAX_DIM];
  4.     char *userid;
  5.     char *passID;
  6.     FILE *fileAutentic=fopen("autenticazione", "");//file per salvare gli utenti rgistrati
  7.     if(fileAutentic==NULL)
  8.         ERRORE("errore nella fopen\n");
  9.        
  10.     while(!feof(fileAutentic)){
  11.         int userID = fscanf(fileAutentic, "%s", &userid)
  12.         if(userID==-1)
  13.             ERRORE("errore nella fscanf\n");
  14.        
  15.         while(userID!=0){// userID!=0, quindi ha letto un user
  16.             if(strcmp(temp,user)==0){ // vede se l'user passato è presente nel file
  17.                
  18.             int password = fscanf(fileAutentic, "%s", &passID) {
  19.                 if(password==-1)
  20.                     ERRORE("errore nella fscanf\n");
  21.             }
  22.             if(strcmp(temp,pass)==0){ // confronta le password
  23.                 ris=1;// sono uguali, quindi l'utente già è presente;
  24.             }
  25.         }
  26.     }
  27.     if(ris==0){// l'utente non c'è, si deve iscrivere
  28.         int registraUser=fprintf(fileAutentic,"%s\n",user);
  29.         if(registraUser<0) ERRORE("errore nella read\n");
  30.         int registraPass=fprintf(fileAutentic,"%s\n",pass);
  31.         if(registraPass<0) ERRORE("errore nella read\n");
  32.         ris=1; //l'utente è si è appena registrato, non ha una sua lista messaggi, la si deve creare
  33.         lista=nuovaListaMess();
  34.     }  
  35.     int close=fclose(fileAutentic);
  36.     if (close < 0) ERRORE("errore nella fclose\n");
  37.     return ris;
  38. }
Add Comment
Please, Sign In to add comment