Perl Login Script

JD Austin plug-discuss@lists.plug.phoenix.az.us
Mon, 11 Feb 2002 13:56:05 -0700


I tested this out, only friend/foe passes.  :

#!/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 = undef;             # simply dealing with the hash so that it's
more obvious
$authusers{'friend'}='foe';   # $authusers{user}=password;

$userid=$q->param('demid');
$password=$q->param('dempwd');
if ( $authusers{$userid} == $password and (defined($authusers{$userid})) ) {

print $q->header,                    # create the HTTP header
       $q->start_html("Hello $userid" ), # start the HTML
              $q->h1('You are authorized...'),         # level 1 header
              $userid,  $q->end_html;                  # end the HTML --
took out what didn't make sense
              #I wasn't sure what you were trying to print above, so I took
all out except for the title and userid.

                     }
                     else
                     {
                     print $q->header,$q->start_html("else"),
                     $q->h1('Failed...'),
                     $q->end_html;
                     }

----- Original Message -----
From: "Roderick" <rford@asu.edu>
To: "plug-discuss" <plug-discuss@lists.plug.phoenix.az.us>
Sent: Monday, February 11, 2002 11:57 AM
Subject: Perl Login Script


> 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>
>
> ________________________________________________
> See http://PLUG.phoenix.az.us/navigator-mail.shtml if your mail doesn't
post to the list quickly and you use Netscape to write mail.
>
> PLUG-discuss mailing list  -  PLUG-discuss@lists.plug.phoenix.az.us
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>