Home » Javascript » How to determine post request inputs using javascript

How to determine post request inputs using javascript

Posted by: admin June 30, 2018 Leave a comment

Questions:

I am trying to login to a website using python but not having much success. Whenever I post my credentials, I get a 200 response but I’m redirected to the login screen. I think this is because the website’s login is using javascript that requires more than just a username and password in the post command, but I’m not sure how to parse it to fix my login code.

This is my python code:

s = requests.session()
login_url = "example.com"
result = s.get(login_url)
payload = {
    "user_login": "xx", 
    "user_pass": "xx"
}
print(payload)
postresult = s.post(
    login_url, 
    data = payload,
    allow_redirects=True
)

Here’s what the input form looks like:

<div id="loginForm">
        <ul>
            <li>
                <label>Email:</label>
                <input class="txt" type="email" name="user_login" tabindex="1" value="">
            </li>
            <li>
                <label>Password:</label>
                <input class="txt" type="password" name="user_pass" tabindex="2">
            </li>
            <li class="submit">
                <a id="a-fgt" class="sub" href="#" tabindex="4">Forgot Password</a>
                <input type="submit" id="logSubmit" value="Login" tabindex="3" />
                <div id="rightBlock">
                    <span id="respMsg"></span>
                </div>
            </li>
        </ul>
    </div>

And here’s part of the javascript code that’s executing:

function init_login(){
    var form = document.forms.loginForm;
        $submit(form,login_request);
        $listen($('a-fgt'),'click',function(){buildForgotPassword(false);},false);

    var lgn = getCookie('login');
        if(lgn){form.user_login.value = lgn;}
        form[wordCount(form.user_login.value)?'user_pass':'user_login'].focus();

        formVal = new FormValidator(form);
}


/*---\\ LOGIN FUNCTIONS ///---*/
    function login_request(form){
        form = validateForm(form, 'user_pass');
        $post("/JSMX/admin_login.cfc?method=login",login_response,form);
    }
Answers: