#!/usr/bin/perl -w
use strict;
use CGI qw/:standard/;
CGI::initialize_globals();
print header;
print start_html($ENV{'QUERY_STRING'});
if (!defined(param('j_username'))) {
print start_form(-name=>'a_form', -method=>'GET', -action=>'login.cgi');
print textfield(-name=>'j_username');
print br,password_field(-name=>'j_password');
print br,submit();
print end_form;
} else {
if ((defined(param('j_password'))) and (param('j_password') eq '1234')) {
print h1('YEAH!');
} else {
print h1('Bummer, wrong password!');
}
}
print end_html;
1;
####
#!/usr/local/bin/perl -w
use strict;
use warnings;
use WWW::Mechanize;
my $url = 'http://localhost/cgi-bin/login.cgi';
my $ua = WWW::Mechanize->new();
my $user = 'foobie';
my $clearpass = '1999';
$ua->get($url);
#$ua->form_number('1');
#$ua->field('j_username',$user);
#$ua->field('j_password',$clearpass);
#$ua->submit();
$ua->set_fields("j_username" => $user, "j_password" => $clearpass);
$ua->submit();
if ($ua->success())
{ print "Yay!"; }
else
{ print "Login failed: " . $ua->response->status_line; }
####
# from perl -d node_298151.pl
DB<7> p $ua->res->{'_content'}
j_username=
foobie&j_password=1999
Bummer, wrong password!
DB<8>