0

I am trying to login to the site : https://cube.tradejini.com/#/ and retrieve the cookie information.

below is my html code.. but its failing at validating the credentials, anyone please guide.. as I am novice to VBA.

Also note that the webpage takes 3 fields for the validation. username, password and a question.

url = "https://cube.tradejini.com/#/"

With CreateObject("WinHttp.WinHttpRequest.5.1")
    .Open "POST", url, False
    .setRequestHeader "REFERER", url
    .setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
    .setRequestHeader "content-type", "application/json"
    .setRequestHeader "Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
    .setRequestHeader "Accept-Language", "en-us,en;q=0.5"
    .setRequestHeader "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
    .SetCredentials "TSUser1", "Password", "1989"
    .send        
strCookie = .GetAllResponseHeaders

End With
Kiran
  • 167
  • 1
  • 9

1 Answers1

1

You won't be able to use SetCredentials() with that website as the login uses the form body of the POST to submit your login credentials in this format:

"jData=

{
    "uid":"TESTUSER1",
    "pwd":"580c16cbb8092433538a5155ad8852974a1f44fe38bf9cc975cbe86a35639d18",
    "factor2":"1985",
    "apkversion":"20220318",
    "imei":"da30a574e60f7a54e4beecfb9ea701d9",
    "vc":"NOREN_WEB",
    "appkey":"87b39b109b81a7b3a0173370043304a9ebfc8af19593d9acc9b5fdef7669bdc9",
    "source":"WEB",
    "addldivinf":"Chromium Edge-105.0.1343.33"
}"

Where uid = the username, pwd = password factor2 = date of birth. Notice that the password is hashed when submitted, but it is not salted so the same password == same hash. Press F12 in a browser -> fill in your login information -> in the dev tools > network tab click on QuickAuth and select the payload tab to see the hash of your password. Here is a post that goes over sending a JSON object in a POST form body using VBA that you can follow to format your code. Also, side note - that third parameter in SetCredentials() is for a flag denoting whether the request is going to a proxy or directly to a server. You wouldn't be able to use it for your date of birth.

Arpan3t
  • 61
  • 4
  • Thank you for the quick response, just want to confirm below things. 1.So Can I use selenium to login? also I need to send a Jkey along with the above format.. like at the end of jdata like below format jData={ "uid":"TSXXXX", "exch":"NFO", "token":"NIFTY15SEP22C17850", "st":"1663112395", "et":"1663141716", "intrv":"1" }&jKey=37d18ea283efe747420110350dd89dfa784622b2ef4e80d4a8c35281c2abc00a How to send it. I asked this question at: https://stackoverflow.com/questions/73717444/extracting-the-data-using-post-request can u pls guide me – Kiran Sep 14 '22 at 15:07
  • ArPan3t, still I am not getting "set-cookie" value after I've followed ur suggestion.. I am getting connection-Live but set-cookie is not gettign returned. – Kiran Sep 14 '22 at 18:27
  • I am getting only follow items in response header but not set-cookie .below is the output Connection: Keep-Alive Date: Wed, 14 Sep 2022 18:13:06 GMT Keep-Alive: timeout=5, max=100 Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 Content-Language: en Accept-Ranges: bytes Server: Apache Vary: accept-language,accept-charset X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN – Kiran Sep 14 '22 at 18:30
  • Sorry I didn't get to the part of your question involving the cookies. I believe set-cookie is used by the server to set the cookies to be returned. You want to get your requestheaders and parse the cookies from them. [Here](https://stackoverflow.com/questions/64292885/how-to-get-cookie-information-using-excel-vba) is a stack link detailing how to do this. There is no jKey in the request payload when I viewed it in the browser dev tools so I am not sure where that is coming from or why you think you need it. – Arpan3t Sep 14 '22 at 21:00
  • Hey Arpan3t, thanks again, the Jkey is the set-cookie which I need to send to connect to other link its payload looks like below jData={ "uid":"TSXXXX", "exch":"NFO", "token":"NIFTY15SEP22C17850", "st":"1663112395", "et":"1663141716", "intrv":"1" }&jKey=37d18ea283efe747420110350dd89dfa784622b2ef4e80d4a8c35281c2abc00a From you I know till Jdata part, but can I attach the jkey to json like postdata = {jdata} & jkeystring while connecting the other website. (note this is to connect to other url by passing the set-cookie which we got after login) – Kiran Sep 15 '22 at 01:02
  • The body of the POST is different from the header. If you're using set-cookie it will put the value in the cookies section of the header of the POST. Do you need it in both locations (body and header)? A screenshot of the payload from the browser dev tools would be helpful. Since I don't have valid credentials I cannot test myself. – Arpan3t Sep 15 '22 at 13:42
  • Arpan3t, again thank you for the response, although I got the idea, but I am trying with different approach through python scripts. Again thanks for your time. I am going to revisit the vba approach soon. – Kiran Sep 15 '22 at 14:29