Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Form authentication for .NET sites

by Charli (Initiate)
on May 04, 2015 at 02:49 UTC ( [id://1125540]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I am new in Perl and I am trying to go through a login page and going to the actual site. For example, to be able to check emails in Yahoo, one must go through the Yahoo log in to enter credentials for username and password. I used WWW::Mechanize to go through the login page, see code snippet below:
my $mech = WWW::Mechanize->new(); $mech->get($url); $mech->field("UserName", $username); $mech->field("Password", $password); $mech->submit_form();
But with the code above, I am unable to go through the actual page and stuck in the login page. Any thoughts or suggestions?

Replies are listed 'Best First'.
Re: Form authentication for .NET sites
by thomas895 (Deacon) on May 04, 2015 at 03:28 UTC

    The form you are trying to use probably uses JavaScript to fill in some fields when you press the submit button. Try using your browser's development tools to see what else is being sent to the server.

    With ASP.NET, I know that there is a __doPostBack function that is sometimes called prior to submitting the form, or even WebForm_DoPostBackWithOptions. The latter one usually means that the form is being sent to someplace other than the current page. If you designed this application yourself, you probably want to look at the ASP.NET manuals.

    -Thomas
    "Excuse me for butting in, but I'm interrupt-driven..."

      Hi Thomas, thank you so much for your answers.

      Yes, I can confirm that the site uses JavaScript. The login site is not ours, but we must go through that for us to be able to go through our site. Below is a code snippet of the HTML form.
      <div id="loginArea"> <div id="loginMessage" class="groupMargin">Sign in with your a +ccount</div> <form method="post" id="Login" autocomplete="off" novalidate=" +novalidate" onkeypress="if (event &amp;&amp; event.keyCode == 13) Login.submitLoginRequest();" action=""> <div id="formsAuthenticationArea"> <div id="userNameArea"> <input id="userNameInput" name="UserName" type="em +ail" value="" tabindex="1" class="text fullWidth" spellcheck="false" +placeholder="Username" autocomplete="off"> </div> <div id="passwordArea"> <input id="passwordInput" name="Password" type="p +assword" tabindex="2" class="text fullWidth" placeholder="Password" a +utocomplete="off"> </div> <div id="kmsiArea" style="display:none"> <input type="checkbox" name="Kmsi" id="kmsiInput" +value="true" tabindex="3"> <label for="kmsiInput">Keep me signed in</label> </div> <div id="submissionArea" class="submitMargin"> <span id="submitButton" class="submit" tabindex="4 +" onkeypress="if (event &amp;&amp; event.keyCode == 32) Login.submitL +oginRequest();" onclick="return Login.submitLoginRequest();">Sign in< +/span> </div> </div> </form> </div>

      Any suggestions or advice on how to go about the form?

      Thanks, Charli

        There could be other JavaScript doing things with the form that isn't visible in your snippet. Again, try to use the development tools (try Ctrl-Shift-K, Ctrl-Shift-I, or right-click and select "Inspect Element") to see what else is sent to the server.
        You should be able to figure it out pretty easily, otherwise the manuals are never far away.

        -Thomas
        "Excuse me for butting in, but I'm interrupt-driven..."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1125540]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found