ogmogul has asked for the wisdom of the Perl Monks concerning the following question:

I've spent the last several days looking for a solution to this issue and while I've tried several suggested solutions (in reading) all have failed. Ultimately what I want to do is just log into this site, from there I can take care of the rest. I know that the username is being passed successfully over, it's just the password is not being passed (I believe).

Courtesy of Data::Dumper here is the form and associated fields from the page:
$VAR1 = bless( { 'default_charset' => 'UTF-8', 'enctype' => 'application/x-www-form-urlencoded', 'accept_charset' => 'UNKNOWN', 'action' => bless( do{\(my $o = 'http://*_edit_*/proc +login')}, 'URI::http' ), 'method' => 'POST', 'attr' => { 'method' => 'POST', 'id' => 'fLogin' }, 'inputs' => [ bless( { 'value_name' => '', 'value' => '', 'name' => 'txtUserID', 'class' => 'TextInput', 'id' => 'txtUserID', 'type' => 'text', 'size' => '20' }, 'HTML::Form::TextInput' ), bless( { 'readonly' => 1, 'value_name' => '', 'value' => '', 'name' => 'sessionTermNum', 'id' => 'sessionTermNum', 'type' => 'hidden', 'size' => '20' }, 'HTML::Form::TextInput' ), bless( { 'value_name' => '', 'value' => '', 'onkeypress' => 'return vfnChe +ckKeyLogin(event);', 'name' => 'txtPassword', 'class' => 'TextInput', 'id' => 'txtPassword', 'type' => 'password', 'size' => '20' }, 'HTML::Form::TextInput' ), bless( { 'readonly' => 1, 'value_name' => '', 'value' => 'login', 'name' => 'cmd', 'id' => 'cmd', 'type' => 'hidden', 'size' => '20' }, 'HTML::Form::TextInput' ) ] }, 'HTML::Form' );
Here is my simple code that I believe should be working and I'm unable to figure out why:
#!/usr/bin/perl -w use strict; use WWW::Mechanize; use Data::Dumper; use LWP; my ($user,$pass) = ("$ARGV[0]","$ARGV[1]"); $user = chomp($user);$pass = chomp($pass); my $mech = WWW::Mechanize->new(); $mech -> cookie_jar(HTTP::Cookies->new()); $mech -> get('http://*_edit_*/Login.jsp'); $mech -> submit_form( form_id => 'fLogin', fields => { txtUserID => $user, txtPassword => $pass, } ); my $html_raw = $mech -> content(); print "\n$html_raw\n";


Thanks for reading and please excuse my Perlish n3wb c0de.
./Mogul


SOLUTION:

After watching the POST in Chrome's Developer Toolkit>Network Tab, I was able to see that the password was encrypted. I was able to take the string of encrypted text from the POST and hard-code it into my script to validate that I could log in.

Mogul

Replies are listed 'Best First'.
Re: WWW::Mechanize form submit w/ password failing
by Corion (Patriarch) on Nov 06, 2013 at 08:00 UTC

    If all else fails, compare what a Real Browser sends over the wire with what WWW::Mechanize sends. Adapt your code until the bytes your code sends are indistinguishable from what a Real Browser sends.

    A convenient tool are the Mozilla HTTP Live Headers for Firefox. Likely, other browsers have similar tools.

    For WWW::Mechanize, see LWP::Debug on how to enable a dump of the incoming and outgoing data.

    The sledgehammer tool for tracking what really goes over the wire would be Wireshark.

      Thanks for the tips! In Chrome I was able to see that the password was being encrypted in the post after I looked at the network tab in the Developer Toolbox. Thanks for getting my brain on the right track!
Re: WWW::Mechanize form submit w/ password failing
by locked_user sundialsvc4 (Abbot) on Nov 05, 2013 at 22:25 UTC

    This form contains two hidden fields, which will be supplied by the response that you got back from the request for the page.   These fields, with their values, must be included in the list of submitted fields, too ... just as a browser would have done.   Absent this, the host sees incomplete form-input and will not proceed to let you in.