Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.18 KB | None | 0 0
  1. //EL STRUCT
  2. typedef struct{
  3.         char *username;
  4.         char *password;
  5.         struct USUARIO *proximo;
  6. }USUARIO;
  7.  
  8. //LO LLENO ASI :
  9.  
  10. lista = (USUARIO *)malloc(sizeof(USUARIO *));
  11.         lista->username ="cromestant";
  12.         lista->password="12345";
  13.         USUARIO *auxu =(USUARIO *)lista->proximo;
  14.         auxu = (USUARIO *)malloc(sizeof(USUARIO *));
  15.         auxu->username ="cromestant";
  16.         auxu->password ="testpassword";
  17.  
  18.  
  19.  
  20. //funcion que hace el tokenizing del payload ( payload es del tipo username::password::action
  21. //y busca hacer un match
  22. //lista es una variable global que es el primer nodo de la lista enlazada de USUARIO.
  23.  
  24. int processAP(unsigned char * tempap,int sizeAP)
  25. {
  26.         char *token;
  27.         char delims[]=":";
  28.         unsigned char AP[sizeAP];
  29.         int i=0;
  30.         memcpy(AP,tempap,sizeAP);
  31.         USUARIO *temp ;
  32. printf("LLEGUE");
  33.         char *uname = NULL;
  34.         char *passwd =NULL;
  35.         char *action =NULL;
  36.  
  37.         uname = strtok( AP, delims );
  38.         if( uname != NULL )
  39.         {
  40.                 passwd = strtok(NULL,delims);
  41.         }
  42.         if (passwd !=NULL)
  43.         {
  44.                 action = strtok(NULL,delims);
  45.         }//se recibio un token semi-valido, por lo menos tiene la estructura adecuada.
  46.         if ((uname!=NULL)&&(passwd!=NULL)&&(action!=NULL)){
  47.                 temp = lista;
  48.                 while(temp!= NULL){
  49.                         if (strcmp(temp->username,uname)==0)
  50.                         {
  51.                                 //username exists
  52.                                 printf("username OK!  %d\n",i);
  53.  
  54.                                 if(strcmp(temp->password,passwd)==0)
  55.                                 {
  56.                                         //password ok
  57.                                         printf("password OK!\n");
  58.                                         return 1;
  59.                                 }else{
  60.                                 printf("password not ok  %d\n",i);
  61.                                 }
  62.                         }
  63.                                 temp =(USUARIO *)temp->proximo;
  64.                                 i++;
  65.  
  66.                 }
  67.         }
  68. return 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement