skygragon / leetcode-cli

A cli tool to enjoy leetcode!
MIT License
3.64k stars 457 forks source link

Cannot login with premium account #194

Open michaelhly opened 4 years ago

michaelhly commented 4 years ago

Problem Summary

Recently bought premium and can't seem to log in anymore.

How to reproduce

Ran ./bin/leetcode user --login -vv Get: [ERROR] invalid password? (403 forbidden)

Here is the full trace:

[TRACE] initializing all plugins
[TRACE] found plugin: cache=default
[TRACE] found plugin: leetcode=default
[TRACE] found plugin: retry=default
[TRACE] inited plugin: leetcode
[TRACE] inited plugin: retry
[TRACE] inited plugin: cache
login: mylogin
pass: 
[DEBUG] running leetcode.login
[DEBUG] running leetcode.signin
⠋ Signing in leetcode.com[TRACE] REQUEST %s { uri: 'https://leetcode.com/accounts/login/',
  callback: [Function] }
[TRACE] REQUEST %s make request https://leetcode.com/accounts/login/
⠸ Signing in leetcode.com[TRACE] REQUEST %s onRequestResponse https://leetcode.com/accounts/login/ 200 { date: 'Sat, 23 Nov 2019 04:51:13 GMT',
  'content-type': 'text/html; charset=utf-8',
  'transfer-encoding': 'chunked',
  connection: 'close',
  'set-cookie': [...],
  vary: 'Accept-Encoding, Cookie',
  'x-frame-options': 'SAMEORIGIN',
  'cf-cache-status': 'DYNAMIC',
  'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
  'x-content-type-options': 'nosniff',
  'expect-ct':
   'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
  server: 'cloudflare',
  'cf-ray': '...' }
[TRACE] REQUEST %s reading response's body
[TRACE] REQUEST %s finish init function https://leetcode.com/accounts/login/
⠼ Signing in leetcode.com[TRACE] REQUEST %s response end https://leetcode.com/accounts/login/ 200 { date: 'Sat, 23 Nov 2019 04:51:13 GMT',
  'content-type': 'text/html; charset=utf-8',
  'transfer-encoding': 'chunked',
  connection: 'close',
  'set-cookie': [...],
  vary: 'Accept-Encoding, Cookie',
  'x-frame-options': 'SAMEORIGIN',
  'cf-cache-status': 'DYNAMIC',
  'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
  'x-content-type-options': 'nosniff',
  'expect-ct':
   'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
  server: 'cloudflare',
  'cf-ray': '...' }
[TRACE] REQUEST %s end event https://leetcode.com/accounts/login/
[TRACE] REQUEST %s has body https://leetcode.com/accounts/login/ 32265
[TRACE] REQUEST %s emitting complete https://leetcode.com/accounts/login/
[TRACE] REQUEST %s { url: 'https://leetcode.com/accounts/login/',
  headers:
   { Origin: 'https://leetcode.com',
     Referer: 'https://leetcode.com/accounts/login/',
     Cookie:
      <hidden> },
  form:
   { csrfmiddlewaretoken: '...',
     login: 'redacted_login',
     password: 'redacted_password' },
  callback: [Function],
  method: 'POST' }
[TRACE] REQUEST %s make request https://leetcode.com/accounts/login/
[TRACE] REQUEST %s onRequestResponse https://leetcode.com/accounts/login/ 403 { date: 'Sat, 23 Nov 2019 04:51:14 GMT',
  'content-type': 'text/html; charset=utf-8',
  'transfer-encoding': 'chunked',
  connection: 'close',
  'set-cookie': [ ...],
  vary: 'Cookie',
  'x-frame-options': 'SAMEORIGIN',
  'cf-cache-status': 'DYNAMIC',
  'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
  'x-content-type-options': 'nosniff',
  'expect-ct':
   'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
  server: 'cloudflare',
  'cf-ray': '...' }
[TRACE] REQUEST %s reading response's body
[TRACE] REQUEST %s finish init function https://leetcode.com/accounts/login/
[TRACE] REQUEST %s response end https://leetcode.com/accounts/login/ 403 { date: 'Sat, 23 Nov 2019 04:51:14 GMT',
  'content-type': 'text/html; charset=utf-8',
  'transfer-encoding': 'chunked',
  connection: 'close',
  'set-cookie': [...],
  vary: 'Cookie',
  'x-frame-options': 'SAMEORIGIN',
  'cf-cache-status': 'DYNAMIC',
  'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
  'x-content-type-options': 'nosniff',
  'expect-ct':
   'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
  server: 'cloudflare',
  'cf-ray': '...' }
[TRACE] REQUEST %s end event https://leetcode.com/accounts/login/
[TRACE] REQUEST %s emitting complete https://leetcode.com/accounts/login/
[ERROR] invalid password?

Environment

yishanhe commented 4 years ago
csrfmiddlewaretoken: xxx
login: xxx
password: xxx
next: /
recaptcha_token: xxx

Not familiar with this, but I check the request/response on leetcode website and saw this recaptcha_token, can anyone educate me what is effect of this token here? Thanks.

chishui commented 4 years ago

https://developers.google.com/recaptcha/intro

Welcome to the reCAPTCHA developer documentation.

reCAPTCHA protects you against spam and other types of automated abuse. Here, we explain how to add reCAPTCHA to your site or application.

kgfly commented 4 years ago

+1, code here https://github.com/leetcode-tools/leetcode-cli does not work either.

huangyingw commented 4 years ago

most probably, leetcode recently enhance the security set of its API, that's why our login request failed. I am trying to fix this issue, but no luck yet...

wey-gu commented 4 years ago

I am not handly on JS, possibly this captcha-solver may help? Thanks!

rgatti commented 4 years ago

It seems I'm able to get the cli working by manually logging into the site in a browser, viewing the cookies, and creating the ~/.lc/leetcode/user.json by hand. My file looks like ...

{
  "login": "[username]",
  "loginCSRF": "",
  "sessionCSRF": "[copied from csrftoken]",
  "sessionId": "[copied from LEETCODE_SESSION]"
}

Currently, I've only tested showing my account status and listing problems.

dorianHe commented 4 years ago

It seems I'm able to get the cli working by manually logging into the site in a browser, viewing the cookies, and creating the ~/.lc/leetcode/user.json by hand. My file looks like ...

{
  "login": "[username]",
  "loginCSRF": "",
  "sessionCSRF": "[copied from csrftoken]",
  "sessionId": "[copied from LEETCODE_SESSION]"
}

Currently, I've only tested showing my account status and listing problems.

I am trying your tips. But I don't know how can I find my LEETCODE_SESSION. Could you tell me where I can find it?

rgatti commented 4 years ago

It seems I'm able to get the cli working by manually logging into the site in a browser, viewing the cookies, and creating the ~/.lc/leetcode/user.json by hand. My file looks like ...

{
  "login": "[username]",
  "loginCSRF": "",
  "sessionCSRF": "[copied from csrftoken]",
  "sessionId": "[copied from LEETCODE_SESSION]"
}

Currently, I've only tested showing my account status and listing problems.

I am trying your tips. But I don't know how can I find my LEETCODE_SESSION. Could you tell me where I can find it?

After logging into LeetCode I'm using the storage inspector to grab the cookie values, https://developer.mozilla.org/en-US/docs/Tools/Storage_Inspector.

dorianHe commented 4 years ago

It seems I'm able to get the cli working by manually logging into the site in a browser, viewing the cookies, and creating the ~/.lc/leetcode/user.json by hand. My file looks like ...

{
  "login": "[username]",
  "loginCSRF": "",
  "sessionCSRF": "[copied from csrftoken]",
  "sessionId": "[copied from LEETCODE_SESSION]"
}

Currently, I've only tested showing my account status and listing problems.

I am trying your tips. But I don't know how can I find my LEETCODE_SESSION. Could you tell me where I can find it?

After logging into LeetCode I'm using the storage inspector to grab the cookie values, https://developer.mozilla.org/en-US/docs/Tools/Storage_Inspector.

Thank you very much for the quick reply!

rony36 commented 4 years ago

I sovled this problem by using cookie.chrome plugin. Seems need to disable some other plugins to make it works.

leetcode plugin -d leetcode.cn
leetcode plugin  -d lintcode
leetcode user -l -v
mmurshed commented 4 years ago

I faced the same problem. Even after using the token I get locked question error with my premium account.

luxp commented 4 years ago

You can try this workshop based on leetcode-cli for workaround: https://github.com/luxp/leetcode-workshop-javascript

Instead of submit with cli, it will automatically copy the submit content to the clipboard and open the problem page. You just need to paste it.

And by the way, you can use jest to test your code locally, which is really helpful and fast for debug and verification.

orifmilod commented 3 years ago

For those who want to find data below, just go to chrome and paste this chrome://settings/cookies/detail?site=leetcode.com

{
  "login": "[username]",
  "loginCSRF": "",
  "sessionCSRF": "[copied from csrftoken]",
  "sessionId": "[copied from LEETCODE_SESSION]"
}

Edit:

It seems like the link above no longer works: Go to leetcode.com and open inspect tab Paste this in the console and press enter: Object.fromEntries(document.cookie.split('; ').map(v=>v.split(/=(.*)/s).map(decodeURIComponent)))

Then you should see it return your cookies. You can then copy sessionCSRF from csrftoken and sessionId from [xxxxxxxx]_gr_session_id

songyu-wang98 commented 2 years ago

For those who want to find data below, just go to chrome and paste this chrome://settings/cookies/detail?site=leetcode.com

{
  "login": "[username]",
  "loginCSRF": "",
  "sessionCSRF": "[copied from csrftoken]",
  "sessionId": "[copied from LEETCODE_SESSION]"
}

love u bro

shalimujiang commented 2 years ago

For those who want to find data below, just go to chrome and paste this对于那些想在下面找到数据的人,只需转到 chrome 并粘贴即可 chrome://settings/cookies/detail?site=leetcode.comchrome://settings/cookies/detail?site=leetcode.com

{
  "login": "[username]",
  "loginCSRF": "",
  "sessionCSRF": "[copied from csrftoken]",
  "sessionId": "[copied from LEETCODE_SESSION]"
}

The plugin was working fine before then I uninstalled and reinstalled vim as well as installed the plugin and couldn't log in later. I tried your method, I don't know what I filled in wrong, can you correct me? Thank you! image image image Linux localhost 5.10.43 #1 SMP PREEMPT Thu Aug 18 17:40:54 CST 2022 aarch64 Android (WJXN76O4$}FCX94W%`KWQ6

orifmilod commented 1 year ago

@shalimujiang I have made an edit in my comment above and I think the values can be obtained using another way. Hope it works :)

dsshay commented 6 months ago

@shalimujiang how you launch command "leetcode user -l" using user.json?