Perl Login Script

Victor Odhner plug-discuss@lists.plug.phoenix.az.us
Mon, 11 Feb 2002 13:46:32 -0700


Hi, Roderick.

This won't work at all:
   if( $q->param('dempwd') == $authusers{$q->param('demid')} ) {
... because == is a numeric compare operator,
not a string compare.

Try perl -d scriptname ... it allows you to step
through a program and see exactly what it's doing.

Of course for a CGI you have to fake the environment,
but cgi.pm is very nice about that:  it prompts you
for the CGI variables, so you can enter:
dempwd=password
demid=user

Vic

Roderick wrote:
> 
> What is wrong here... I need to validate an name=>password pair, from a
> form submission.
> 
> script:
> ----------------------------------
> 
> #!/usr/local/bin/perl -w
> # CGI script that creates a fill-out form
> # and echoes back its values.
> use CGI qw/:standard/;
> $q=new CGI;                        # create new CGI object
> %authusers = ('user','password','friend','foe');
> 
> if( $q->param('dempwd') == $authusers{$q->param('demid')} ) {
> 
> print $q->header,                    # create the HTTP header
>        $q->start_html("Hello $1" ), # start the HTML
>        $q->h1('You are authorized...'),         # level 1 header
>         $authusers{$q->param('demid')},
>         $q->param('name'),
>        $q->end_html;                  # end the HTML
> 
> }
> else
> {
> print $q->header,$q->start_html("else"),
>         $q->h1('Failed...'),
>         $q->end_html;
> }
> 
> ---------------------------------------
> and here is the form submission...
> ---------------------------------------
> <form name="login" method="post" action="logint.pl">
>    <p> Demonstrator's ID
>      <input type="text" name="demid">
>    </p>
>    <p>Password
>      <input type="password" name="dempwd" size="20">
>      <input type="submit" name="Login" value="Log In">
>    </p>
> </form>