We help IT Professionals succeed at work.

password checker written in perl

hwihyunee
hwihyunee asked
on
Below is the code i'm having trouble with:
what it's supposed to do is read in from a stream, which contains only ONE string, that is, the password input, then checks it if it's the right one, then puts out an HTML page according to the result.

#!/usr/bin/perl

print "Content-type:text/html\n\n";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
$buffer=~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

if($buffer eq "mypassword"){
print "<html><head><title>Member Directory</title></head><body>";
print "<font face="arial" size="2" color="blue">This is only a test.</font>\n";
print "</body></html>";
}
else{
print "<html><head><title>Lightning from the sky</title></head><body>";
print "<font face="arial" size="2" color="blue">wrong password. try again~.</font>\n";
print "</body></html>";
}

For some reason it doesn't work. HELP ME!

- paul
Comment
Watch Question

CERTIFIED EXPERT

Commented:
why do you not use the CGI library, you will have a easiser life

install the CGI lib and see soem examples on the net

Paul
CERTIFIED EXPERT

Commented:
your solution does only work for method=POST, is this what your html page soes?

Author

Commented:
Yes, i'm using POST as my method. i'm trying to use CGI library as makerp  has advised me too.
CERTIFIED EXPERT

Commented:
what do you get in $buffer? can you please post here.

Author

Commented:
i dont get anything.. i just get a message that reads :internal server error.  something like that...
something's definitely wrong with the code..
CERTIFIED EXPERT
Commented:
if $buffer is empty, you didn't get anything.
If there was an internal server error, did you test if you CGI even have benn executed?

BTW, your $buffer still contains the name=value pairs, probably not what you want. Add following:

# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
        ($name, $value) = split(/=/, $pair);
        $FORM{$name} = $value;      
}
# $FORM{'name-of-your-password-variable'} is probably what you want to check
You need to escape your quotes that are within quotes.

Follow this example line from your code:
print "<font face="arial" size="2" color="blue">This is only a test.</font>\n";
Should be:
print "<font face=\"arial\" size=\"2\" color=\"blue\">This is only a test.</font>\n";

dill
CERTIFIED EXPERT

Commented:
hwihyunee,

Did you get the solution you were looking for?

What solution, if any, did you use?

Do let us know.

Thanks,
CERTIFIED EXPERT

Commented:
hwihyunee,

                     Did you get the solution you were looking for?

                     What solution, if any, did you use?

                     Do let us know.

                     Thanks,
hwihyunee,

In an effort to help clean up the open questions, I am going thru old questions that I have participated in.

This question needs closed either by deleting it or PAQing it.

Please do one of the following:
1. Award points.  If a point split is necessary, post a zero point question in Customer Service specifying how to split them and a link to the question.

2. If you felt any help was worth points, then post a zero point question in the Customer Service area, with a link to the question, asking for points to be reduced then award them.

3. Otherwise, just delete it.

Thanks,
dill
CERTIFIED EXPERT

Commented:
hwihyunee,

The following 3 questions have been open for a long time now & need your urgent attention.

Please take some time to close these questions asap.

EE userid hwihyunee
Total questions asked 4 (100%)
Open questions 3 (75.00%)
       

Topic Area              URL              Date              
CGI   http://www.experts-exchange.com/jsp/qShow.jsp?ta=cgi&qid=20189175   10/01/01  
Macromedia Flash   http://www.experts-exchange.com/jsp/qShow.jsp?ta=flash&qid=20101592   04/04/01  
Perl   http://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20072809   02/05/01  

Your help will be highly appreciated.

Thanks.
Comment from expert accepted as answer.

Thank you
Computer101
E-E Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.