I have two programs, a server (written in C) and a client (Python). I'm trying to set up a simple login system where the client enters a username and password, which are sent to the server via socket connection, and then the server compares the received strings with its stored credentials. I have tried every possible type of string comparison/manipulation I can think of to get a legitimate comparison of the characters in the strings, but it is still saying "password" does not equal "password" etc.
Client (Python):
Code:
print "Username: ",
username = sys.stdin.readline() # Enters "user"
s.send(username)
password = getpass.getpass() # Enters "password"
s.send(password)
And on the server side:
Code:
// Hardcoded credentials (for now)
char *username = "user";
char *password = "password";
...
// Get username from client
bzero(recvbuf, BUFSIZE); // Clear the string buffer for received messages
n = read(acceptfd, recvbuf, BUFSIZE); // Read any incoming messages
cliUsr = recvbuf;
printf("Username: %s", cliUsr); // Prints out "user"
fflush(stdout); // Flush the output buffer
// Get password from client
bzero(recvbuf, BUFSIZE); // Clear the string buffer for received messages
n = read(acceptfd, recvbuf, BUFSIZE); // Read any incoming messages
cliPw = recvbuf;
printf("Password: %s\n", cliPw); // Prints out "password"
fflush(stdout); // Flush the output buffer
if (strcmp(cliUsr, username) == 0 && strcmp(cliPw, password) == 0) {
accessGranted == true;
}
I am going crazy and any help is appreciated. Thanks!
Edit: I changed sys.stdin.readline() to raw_input() and am able to correctly compare strings with C.