Giter VIP home page Giter VIP logo

android-lib-recaptcha's Introduction

Android-Lib-reCAPTCHA

Download Build Status CircleCI Codeship Status for ayltai/Android-Lib-reCAPTCHA Build Status BuddyBuild

This project is no longer maintained

reCAPTCHA v1 is official unsupported since May of 2016 (Link):

reCAPTCHA V1 has been deprecated since May of 2016 and will not work for new sites. reCAPTCHA v1 is no longer supported and continued functionality can not be guaranteed. Please switch to one of the options above.

reCAPTCHA v2 is purely JavaScript based which makes it Android-unfriendly.

The reCAPTCHA Android Library provides a simple way to show a CAPTCHA as an ImageView in your Android app, helping you stop bots from abusing it. The library wraps the reCAPTCHA API.

Screenshot

Quick Start

First you have to sign up for your API keys.

Installation

repositories {
    jcenter()
}

dependencies {
    compile 'android.lib.recaptcha:reCAPTCHA:+'
}

The Layout

To show CAPTCHA image, you need to add a <android.lib.recaptcha.ReCaptcha /> element to your layout XML:

<android.lib.recaptcha.ReCaptcha
    android:id="@+id/recaptcha"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scaleType="centerInside" />

It is important to use android:scaleType="centerInside" to ensure the entire CAPTCHA image can be displayed.

Alternatively, you can create an instance of android.lib.recaptcha.ReCaptcha at runtime:

ReCaptcha reCaptcha = new ReCaptcha(context);

How to show CAPTCHA

In your activity/fragment/view containing android.lib.recaptcha.ReCaptcha, you need display a CAPTCHA image for the user to response:

ReCaptcha reCaptcha = (ReCaptcha)findViewById(R.id.recaptcha);
reCaptcha.showChallengeAsync("your-public-key", onShowChallengeListener);

showChallengeAsync downloads and shows CAPTCHA image asynchronously. It is safe to invoke in UI thread. No exception will be thrown in case of any error by this call. All errors will be treated as unsuccessful in showing CAPTCHA image.

onShowChallengeListener is an instance of ReCaptcha.OnShowChallengeListener, which is called when an attempt to show a CAPTCHA is completed.

The synchronous version of this method is showChallenge.

How to verify user input

To verify user input, pass the input string to ReCaptcha.verifyAnswerAsync (or ReCaptcha.verifyAnswer):

reCaptcha.verifyAnswerAsync("your-private-key", "user-input", onVerifyAnswerListener);

verifyAnswerAsync asynchronously submits the user input string to reCAPTCHA server for verification. It is safe to invoke in UI thread. No exception will be thrown in case of any error by this call. All errors will be treated as verification failure.

onVerifyAnswerListener is an instance of ReCaptcha.OnVerifyAnswerListener, which is called when an attempt to verify the user input is completed.

The synchronous version of this method is verifyAnwser.

Specify a locale

You can force the widget to render in a specific language. Please refer to this page.

reCaptcha.setLanguageCode("fr");

Sample Application

A complete sample application is available at https://github.com/ayltai/Android-Lib-reCAPTCHA/tree/master/reCAPTCHA-Samples.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.