DEV Community

Cover image for How to Bypass Captcha in Dart Using 2Captcha?
Pankaj Das
Pankaj Das

Posted on

How to Bypass Captcha in Dart Using 2Captcha?

CAPTCHA was developed so that while a machine couldn't read the text, a person could. However, in practice, this rarely succeeds because almost every single simple text captcha uploaded to the website is resolved in a few months or less. ReCaptcha v2, which is trickier but still passable in automated mode, follows next.

In this, we will see how a developer can use reCATCHA in a shopping application built using Dart language. You can also use 2Captcha, one of the leading captcha solving software in the world, which is helpful for developers to make their signup or signing process smooth.

A security technology known as CAPTCHA authentication is used to distinguish between computers and humans. A fully automated public Turing test is CAPTCHA. CAPTCHA helps shield you against spam and password decryption by forcing you to correctly complete a brief test that establishes you are a human and not a computer trying to access a password-protected account.

Recaptcha validation uses Advanced risk analysis methods to differentiate between human and automated users. The captcha will present a challenge to confirm your identity if it finds any spam.

Two straightforward components make up a CAPTCHA test: a text box and a random sequence of letters and/or numbers that appear as a warped image. Simply enter the characters you see in the image into the text box to pass the test and demonstrate your human identity.

In this, we will see how a developer can use reCATCHA in an application built using Flutter technology. You can also use 2Captcha, one of the leading captcha-solving software in the world, which is helpful for Flutter developers to make their signup or signing process smooth.

What advantages does a captcha offer?

In essence, captchas prevent robot software from submitting fictitious or malicious internet requests, which deters hackers from exploiting online services.

Captcha quizzes can be applied to...

  • By preventing hackers from repeatedly sending in bogus responses using robots, you can preserve the integrity of online polls.

  • Stop allowing hackers to continually attempt to access online accounts using hundreds of different passwords.

  • Stop hackers from creating several email accounts that they would later use for illegal activities.

  • Stop online criminals from spamming news or blog posts with questionable comments and links to other websites.

  • Stop the use of robots by ticket touts to purchase a large number of concert and show tickets.

How to implement recaptcha in Dart Language?

As a developer, you must always be on the lookout for spam data anytime you construct forms to collect information from users online. Hackers can insert automated bots into the form to fill it with harmful code activity and gain access to the backend of your website.

*Flutter_recaptcha_v2 *

This plugin is used for google rechaptcha v2.you have get reference from here.

Add it in your **pubspec.ymal** file run below command.
Enter fullscreen mode Exit fullscreen mode

flutter pub add flutter_recaptcha_v2

Google ReCaptcha must be used in Webview for this plugin to work. It only works with Google ReCAPTCHA V2 with this plugin.in flutter sdk 2.5.0

Put the RecaptchaV2 widget into your widget tree, make sure it is at the top of the tree, and block all of the interactions from behind. You can modify the RecaptchaV2's plugin URL for the captcha domain or leave it as is by omitting the line that reads.

pluginURL = "https://recaptcha-flutter-plugin.firebaseapp.com/";
Enter fullscreen mode Exit fullscreen mode

Add this recaptcha code to your app.

RecaptchaV2Controller recaptchaV2Controller = RecaptchaV2Controller();
...
RecaptchaV2(
    apiKey: "YOUR_API_KEY", // for enabling the reCaptcha
    apiSecret: "YOUR_API_SECRET", // for verifying the responded token
    pluginURL: "https://mypersonalurl.com",
    visibleCancelBottom: true,
    textCancelButtom: "CUSTOM CANCEL CAPTCHA BUTTOM TEXT",
    controller: recaptchaV2Controller,
    onVerifiedError: (err){
        print(err);
    },
    onVerifiedSuccessfully: (success) {
        setState(() {
            if (success) {
                // You've been verified successfully.
            } else {
                // "Failed to verify.
            }
        });
    },
),
Enter fullscreen mode Exit fullscreen mode

Here we will learn how to build a SignIn screen with captcha verification. In this, we have to take the id and password from the user and verify the captcha.

Let’s see the full source code:

main.dart file

import 'package:flutter/material.dart';
import 'package:flutter_recaptcha_v2/flutter_recaptcha_v2.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}
class MyHomePage extends StatefulWidget {
  const MyHomePage({
    Key key,
  }) : super(key: key);
  @override
  _MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
  String verifyResult = "";
  TextEditingController nameController = TextEditingController();
  TextEditingController passwordController = TextEditingController();
  RecaptchaV2Controller recaptchaV2Controller = RecaptchaV2Controller();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Sign Up Screen"),
      ),
      body: Stack(
        children: <Widget>[
          Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Padding(
                    padding: const EdgeInsets.all(10),
                    child: Column(
                      children: <Widget>[
                        Container(
                            alignment: Alignment.center,
                            padding: const EdgeInsets.all(10),
                            child: const Text(
                              'Sign In',
                              style: TextStyle(
                                  color: Colors.blue,
                                  fontWeight: FontWeight.w500,
                                  fontSize: 30),
                            )),
                        Container(
                          padding: const EdgeInsets.all(10),
                          child: TextField(
                            controller: nameController,
                            decoration: const InputDecoration(
                              border: OutlineInputBorder(),
                              labelText: 'User Name',
                            ),
                          ),
                        ),
                        Container(
                          padding: const EdgeInsets.all(10),
                          child: TextField(
                            obscureText: true,
                            controller: passwordController,
                            decoration: const InputDecoration(
                              border: OutlineInputBorder(),
                              labelText: 'Password',
                            ),
                          ),
                        ),
                        TextButton(
                          onPressed: () {
                            //forgot password screen
                          },
                          child: const Text(
                            'Forgot Password',
                          ),
                        ),
                        Container(
                          height: 50,
                          padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
                          child: ElevatedButton(
                            child: const Text('Login'),
                            onPressed: (){},
                          ),
                        ),
                        Row(
                          children: <Widget>[
                            const Text('Already have account?'),
                            TextButton(
                              child: const Text(
                                'Sign in',
                                style: TextStyle(fontSize: 20),
                              ),
                              onPressed: () {},
                            )
                          ],
                          mainAxisAlignment: MainAxisAlignment.center,
                        ),
                      ],
                    )),
              ],
            ),
          ),
          RecaptchaV2(
            apiKey: "6LeCwZYUAAAAAJo8IVvGX9dH65Rw89vxaxErCeou",
            apiSecret: "6LeCwZYUAAAAAKGahIjwfOARevvRETgvwhPMKCs_",
            controller: recaptchaV2Controller,
            onVerifiedError: (err) {
              print(err);
            },
            onVerifiedSuccessfully: (success) {
              setState(() {
                if (success) {
                  verifyResult = "You've been verified successfully.";
                } else {
                  verifyResult = "Failed to verify.";
                }
              });
            },
          ),
        ],
      ),
    );
  }
}

Enter fullscreen mode Exit fullscreen mode

Output:

Bypass Captcah

Conclusion:

This Flutter application shows how to create a login or sign up screen in an application with reCaptcha verification. The majority of commonly used widgets, including Text, TextButton, and ElevatedButton, are encircled by Container widgets. I hope you understand how we implement and use Recaptcha verification in a flutter. You can modify this code according to your needs.

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.