1

I'm trying to write a simple password system for my website. No username, nothing like that, just a password I can distribute to friends. The idea is to pass a value to the small CGI program written in C below:

#include <stdio.h>
#include <stdlib.h>
int main(){
char *test;
printf("Content-Type: text/html\n\n");            //give the content type
test = getenv("QUERY_STRING");                    //get the data
//printf ("%s\n\n", test);                        //print it for debugging purposes
if (test == "test=test") {                        //check for correct password
    printf("<a href=\"home.html\">Enter.</a>");   //give the link if correct
}
else if (test == NULL){
    printf("Error.");
}
else{
    printf("Denied.", test);
}
return(0);
}

The problem is that, no matter what is passed to it, it always prints "Denied". Whenever I print the returned data, it is exactly what I would expect, i.e. "test=test", yet it still prints "Denied". I'm pretty sure I'm doing this correctly, and I wonder if it is a problem with the server (TinyWeb). The HTML form code is below:

<form action="cgi-bin/cgi.exe" method="get">
    <input name="test" placeholder="Password">
    <input type="submit" value="enter">
</form>

1 Answer 1

1

In C, you can't compare strings using ==. Use strcmp.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.