Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Auto login using mechanize module in perl ?

by vasanthgk91 (Sexton)
on Jun 07, 2018 at 10:19 UTC ( [id://1216088]=perlquestion: print w/replies, xml ) Need Help??

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

I am trying to login website using mechanize perl module

That particular website using csrf token.

I am fetching that token and passing parameter to form_token variable.

There is no success. In previous same scenario working ,In that csrf token list websites i can't able to login.

Please help to my code.Last two days i am trying

Below my code is shown

use WWW::Mechanize::GZip; my $mech = WWW::Mechanize::GZip->new( ssl_opts => { SSL_verify_mode => + 'SSL_VERIFY_NONE',verify_hostname => 0 } ); $url = 'https://test.com/signin'; $mech->get($url); my ($csr_input) = $mech->find_all_inputs(name => 'form_token'); my $token = $csr_input->value(); $mech->form_number(1); $mech->field('email',$username); $mech->field('password',$password); $mech->field('signin',''); $mech->field('form_id','signin'); $mech->field('form_token',$token); $mech->field('button_clicked',''); $mech->submit();

Replies are listed 'Best First'.
Re: Auto login using mechanize module in perl ?
by Anonymous Monk on Jun 07, 2018 at 10:31 UTC
    If the form token is already part of the form... Why are you fetching it? Its already part of the form. There is nothing you should be doing about a csrf form token
      Yes i got your point, that token also part of the form. I removed that fetching condition, i added few things ,now working
      $mech->cookie_jar(HTTP::Cookies->new());
      Now logged in properly .. Thank you

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2026-04-13 17:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.