Password Login Authentication in Client Server in C? Updated FREE

Password Login Authentication in Client Server in C?

#ane

  • New D.I.C Head

Reputation: 0

  • View blog
  • Posts: ane
  • Joined: 31-Dec 11

countersign for customer/server chatting

Posted 31 December 2011 - 09:27 AM

I wrote a code for server and client chatting in C, server has a database for client usernames and passwords, whenever client enter server will asked for client username and password.

My plan was working correctly before password department, when I added password section information technology always says you enter wrong countersign!
I think information technology does not enter If condition( z == inputQ[i].password)

This is office of my code, I promise that you can help me.

int main (int argc, char *argv[]) {     int sockfd, newsockfd, portno, clilen;     char buffer[30];     char buffer2[xxx];     struct sockaddr_in serv_addr, cli_addr;     int data_len ,data_len2 , rc;         if((sockfd = socket(AF_INET, SOCK_STREAM, 0))==Error)     {         error("ERROR on accept");     }        bzero((char *) &serv_addr, sizeof(serv_addr));     portno = atoi(argv[i]);     serv_addr.sin_family = AF_INET;     serv_addr.sin_addr.s_addr = INADDR_ANY;     serv_addr.sin_port = htons(atoi(argv[i]));         if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) ==Error)     {         mistake("Error on accept");     }              listen(sockfd, 5);     pid_t pids[10]; int i; int northward = 10;  /* Start children. */ for (i = 0; i < n; ++i) {   if ((pids[i] = fork()) < 0) {     perror("fork");     abort();   } else if (pids[i] == 0) {    clilen = sizeof(cli_addr);    //printf("parent: %d , child  %d\n\n", getppid(),getpid());     while(1)     {         newsockfd = take(sockfd, (struct sockaddr *) &cli_addr, &clilen);         if (newsockfd == ERROR)             {                 mistake("Error on accept");             }                     bzero(buffer,30);         printf("New client connect from port no. %d and IP %s\n" , ntohs(cli_addr.sin_port), inet_ntoa(cli_addr.sin_addr),getppid());    //-----------------------------------------(2) brandish all database (3)         int i;         static const char filename[] = "clientt.txt";         FILE *file = fopen("clientt.txt", "r");         char line[BUFSIZ];         printf("\nname & password of clients:\n\n");         printf("<proper name>, <password>\due north");         i=0;          while ( fgets(line, sizeof line, file) != NULL &&         sscanf(line, "%d %d",&inputQ[i].name,&inputQ[i].password) == 2 ) // insert information into input queue         {             i++;         }          int  s = i; // number of lines in text file (No. of Processes)          for(i = 0 ; i < s ;i++)         {             printf("  %d        %d\n",inputQ[i].name,inputQ[i].countersign);         }    //-----------------------------------------sent WELCOME to client (4)         char *strings[two];  strings[0] = strdup("Welcome");  send(newsockfd,strings[0],30,0);     //-----------------------------------------receve username from client and display information technology (viii)         data_len = recv(newsockfd,buffer,30, 0);                         if (data_len)             {                 buffer[data_len]= '\0';                 printf("user proper name:%s", buffer);                 buffer2[data_len2]= '\0';                 printf("password:%southward", buffer2);                           }     //------------------------------------------server expect for user name                           int z=atoi(buffer);               for(i = 0 ; i < s ;i++)             {                 if(z==inputQ[i].name )                 {                     data_len=1;                     ship(newsockfd,"username is institute",30,0);                      int zz=atoi(buffer2);                          if(zz== inputQ[i].password)                        {                         data_len2=1;                          send(newsockfd,"password is found",30,0);                          send(newsockfd,strings[0],30,0);                                               printf("client's IP ADDRESS:%d, PORT NO.:%d, PARENT ID:%d",inet_ntoa(cli_addr.sin_addr) ,ntohs(cli_addr.sin_port),getppid());                                         data_len = recv(newsockfd,buffer,xxx,0);                     buffer[data_len]= '\0';                     while(strcmp(buffer,"-1")!=0)                     {                     printf("\nClient: %s\n",buffer);                     data_len=recv(newsockfd,buffer,30,0);                     }                     printf("Client disconnected\n");                     close(newsockfd);                        }                                   printf("Password is wrong"); send(newsockfd,"Countersign is wrong",xxx,0); } }             printf("User Name NOT Establish");             send(newsockfd,"username Non institute",30,0);                                                                //-------------------------------------------                }     close(sockfd);     return 0;     exit(0);   } }  /* Wait for children to leave. */ int status; pid_t pid; while (n > 0) {   pid = wait(&status);   printf("Child with PID %ld exited with status 0x%x.\n", (long)pid, status);   --n;  // TODO(pts): Remove pid from the pids assortment. }      }            


Is This A Good Question/Topic? 0

  • +

#2 jimblumberg User is offline

Reputation: 5916

  • View blog
  • Posts: 17,933
  • Joined: 25-December 09

Re: password for client/server chatting

Posted 31 Dec 2011 - 09:40 AM

Quote

I remember it does not enter If condition( z == inputQ[i].password)

What blazon of variable is z, countersign?

You requite us 150 lines of poorly formatted lawmaking that does not fifty-fifty include the variable definitions and expect united states of america to detect your problem in this mess? Yous need to narrow down the problem, post the smallest possible consummate program that illustrates your problem, and ask specific questions based on the code you lot provide.

Jim

#three CTphpnwb User is online

Reputation: 3872

  • View blog
  • Posts: 14,215
  • Joined: 08-August 08

Re: password for customer/server chatting

Posted 31 December 2011 - 09:49 AM

The employ of functions would as well be a expert offset.

#4 JackOfAllTrades User is offline

Reputation: 6260

  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: password for client/server chatting

Posted 31 December 2011 - ten:43 AM

Quote

I wrote a lawmaking for server and customer chatting in C

Wouldn't a more authentic clarification of this be "I Found some code for server and client chatting in C", and "at present I want to add functionality to it simply I accept no thought how to program in C"?

Before yous spring into "writing" a chat server, how about learning the language?

Password Login Authentication in Client Server in C?

DOWNLOAD HERE

Source: https://www.dreamincode.net/forums/topic/261547-password-for-clientserver-chatting/

Posted by: davisacloned.blogspot.com

Comments