Date:

Share:

How To Solve Captcha in JavaScript Using 2Captcha

Related Articles

You may have already solved many quips while submitting a form or registering on the site. The basic purpose of Captcha is to check if the user is a human or a bot. Captcha represents A fully automated public Turing test to differentiate between computers and humans. Captchas are used to stop spam on blogs, access bots and make a website more secure.

Sometimes the captcha is easy to solve, however, some are just a headache for users, it may take minutes to think whether the letter is uppercase or lowercase. Therefore, today users prefer to use captcha solution software.

2Captcha is among those services that help us troubleshoot in seconds. This is a Captcha detection service for solving challenge-response tests called Captcha to determine if the user is human or not.

What is 2Captcha

2Captcha is a Captcha recognition service that solves captures in real time. It also provides image recognition services operated by human intelligence. 2captcha can identify different types of captcha and its API is available for most programming languages. Because the 2 captcha uses the human-based method to solve captches, it provides the opportunity to earn by solving the captchas.

The benefits of 2captcha

  • Provide a high level of accuracy
  • Man-based method for solving caps
  • The average speed of a capcha solution is less than 12 seconds
  • API is available for most popular programming languages
  • Solve all kinds of caps
  • Reliable reCAPTCHA solution service
  • Provide 100% identification service.

How to solve Captcha in JavaScript using 2Captcha

Here I use the Discord registration form which has a captcha for solution using javascript.

When you fill out this form and click Continue, you will see a captcha.

In order to solve the captcha using javascript, we can use two directories named Axius and 2 Captcha. The axes are used to handle all API calls and 2 captcha is used to resolve the captcha. Install the following packages after creating your file.

npm install axios
npm install 2captcha
  • Import these directories into your file
const axios = require("axios");

const Captcha = require("2captcha");
  • Initialize the captcha with your API key, you can get your API key when you sign up. The API_KEY is available in your account dashboard
const solver = new Captcha.Solver("API_KEY");
  • Define an asynchronous function, here we call it registration. We can solve the captcha using the solver we already started and the Hcaptcha is the type of captcha we have on the Discord site. It requires two parameters, the site developer and the URL.
 const register = async () => 
  console.log("solving...");
  const  data  = await solver.hcaptcha(
    "f5561ba9-8f1e-40ca-9b5b-a0b3f719ef34",
    "https://discord.com/register"
  );

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

screely-1636558144895.png

Use try-catch, because it may have some error and within the try, we can perform the Axios call. Here the method is Post and you need to specify the URL of the application.

screely-1636558440402.png

The second parameter is the data you post to the particular site. The value of the captcha key will be data Mentioned earlier. I received the registration form data when I filled out the discord form and it sent a request.

The captcha_key value is null because I have not yet resolved the captcha, so 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);

;

Here’s all the code we talked about, 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();
  • Run your_file_name node, in our case node app.js in terminal.

It will take some time and then you will get a token. We will use the function below to move the token.

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

Paste the above code into your console and it will go directly to the site without solving the captcha.


Summary

This is this article. I hope you found this article useful, if you need any help please let me know in the comments section.

Do you want to buy me coffee, you can do it Here.

Let’s connect Twitter and LinkedIn.

👋 Thanks for reading, see you next time

Source

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Popular Articles