Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 3298

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T01:26:08+00:00 2024-11-26T01:26:08+00:00

How To Solve Captcha in JavaScript Using 2Captcha

  • 61k

You may already solve many captchas while submitting a form or signing up for a website. The basic Captcha goal is to check whether the user is a human or a bot. Captcha stands for Completely Automated Public Turing test to tell Computers and Humans Apart. Captchas are used to stop spamming blogs, accessing bots, and making a website more secure.

Sometimes it is easy to solve the captcha, however, some of them are just a headache to the users, It might take minutes to think whether the letter is in Upper Case or Lower Case. Therefore, nowadays users prefer to use captcha-solving software.

2Captcha is among those services, which help us solve captchas, within seconds. It is a Captcha recognition service for solving challenge-response tests called Captcha to determine whether the user is a human or not.

What is 2Captcha

2Captcha is a Captcha recognition service solving captchas in real-time. It also provides image recognition services powered by human intelligence. 2captcha can recognize different types of captcha and Its API is available for most programming languages. As the 2captcha uses the human-based method to solve captchas, It provides the opportunity to earn by solving the captchas.

Advantages of 2captcha

  • Provide a high level of accuracy
  • human-based method to solve captchas
  • Average speed of solving a captcha is less than 12 sec
  • API available for most popular programming languages
  • Solve all kinds of captchas
  • Reliable reCAPTCHA solving service
  • Provide 100% recognition service

How to solve Captcha in JavaScript using 2Captcha

Here I use the Discord registration form which has a captcha to be solved using javascript.

screely-1636557507479.png

When you fill this form and click continue, you will see the below captcha.

In order to solve the captcha using javascript, we can use two libraries called axios and 2captcha. The axios is used to handle all the API calls and 2captcha is used to solve the captcha. install the bellow packages after creating your file.

npm install axios 
Enter fullscreen mode Exit fullscreen mode

npm install 2captcha 
Enter fullscreen mode Exit fullscreen mode

  • import these libraries to your file
const axios = require("axios");  const Captcha = require("2captcha"); 
Enter fullscreen mode Exit fullscreen mode

  • Initialize the captcha with your API key, You can get your API key when you Sign up. The API_KEY is available on your dashboard at the Account setting
const solver = new Captcha.Solver("API_KEY"); 
Enter fullscreen mode Exit fullscreen mode

  • define an async function, here we call it register. we can solve the captcha using the solver which we already initialized and captcha is the type of captcha that we have on Discord website. It requires two parameters, the Site key and the website URL. The
 const register = async () => {   console.log("solving...");   const { data } = await solver.hcaptcha(     "f5561ba9-8f1e-40ca-9b5b-a0b3f719ef34",     "https://discord.com/register"   ); 
Enter fullscreen mode Exit fullscreen mode

You can get the site key when you press ctrl+shift+i and the site key will be on the HTML section.

screely-1636558144895.png

Use try-catch, as it may have any error and inside the try, we can ake the Axios call. Here the method is Post and you should specify the request URL.

screely-1636558440402.png

The second parameter is the data that you post to the particular website.
The captcha key value will be the data we specify earlier. I got the data when I filled the discord form and it sent a request.

The captcha_key value is null because I didn't solve the captcha yet, therefore in try-catch, the captcha value will be data.

 try {     let result = await axios.post("https://discord.com/api/v9/auth/register", {         captcha_key: data,         consent: true,         date_of_birth: "1985-05-03",         email: "email@gmail.com",         fingerprint: "907561243135578163.UkNRz9ryt1bnxZbz7hqbnZdEgLc",         gift_code_sku_id: null,         invite: null,         password: "mySecretPassword@23",         username: "suhailkakar",      });     console.log(result.data); } catch (e) {     console.log(e); } }; 
Enter fullscreen mode Exit fullscreen mode

Here is all the code that we explained, call your function at the end of the program.

 const axios = require("axios"); const Captcha = require("2captcha");  const solver = new Captcha.Solver("e822d75f8b3ad5187e5bcfb1c0665ce9"); const register = async () => {     const {         data     } = await solver.hcaptcha(         "f5561ba9-8f1e-40ca-9b5b-a0b3f719ef34",         "https://discord.com/register"     );      try {         let result = await axios.post("https://discord.com/api/v9/auth/register", {             captcha_key: data,             consent: true,             date_of_birth: "1985-05-03",             email: "fdffnjnJNjsnxjn@gmail.com",             fingerprint: "907561243135578163.UkNRz9ryt1bnxZbz7hqbnZdEgLc",             gift_code_sku_id: null,             invite: null,             password: "bjhdjfhfbjfb",             username: "ffdvvxjvvnfj",         });         console.log(result.data);     } catch (e) {         console.log(e);     } }; register();  
Enter fullscreen mode Exit fullscreen mode

  • Run node your_file_name, in our case node app.js on the terminal.

It will take a bit of time and then you will receive a token. We will use the below function to pass the token and

function login(token) {     setInterval(() => {         document.body.appendChild(document.createElement `iframe`).contentWindow.localStorage.token = `"${token}"`     }, 50);     setTimeout(() => {         location.reload();     }, 2500); }  
Enter fullscreen mode Exit fullscreen mode

Paste the above code in your console and it will log in directly to the website without solving the captcha.


Conclusion

That is it for this article. I hope you found this article useful, if you need any help please let me know in the comment section.

Would you like to buy me a coffee, You can do it here.

Let's connect on Twitter and LinkedIn.

👋 Thanks for reading, See you next time

javascriptwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.