Shiv Deepak
Shiv Deepak

Reputation: 3116

Captcha With Google AppEngine

I have a website where i want to put a custom made captcha, can't use online captcha services due to layout needs. It runs on google appengine. Does appengine API has a something for writing characters on a given image?

I went through appengine Python Image API but it doesnot seems to be of much help.

Any suggestions how to generate captcha on google appengine infrastructure?

Upvotes: 1

Views: 2213

Answers (5)

Adam Crossland
Adam Crossland

Reputation: 14213

A quick google search will provide you with plenty of guides for integrating captch services with your AppEngine application. Here's one that uses reCaptcha.

Upvotes: 8

user1788142
user1788142

Reputation: 101

You can use following code to create Captcha, Please note you have to add commons-lang-2.5.jar in your classpath.

        String secutiryCode = RandomStringUtils.random(5, new char[]{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'});
        req.getSession().setAttribute("secutiryCode", secutiryCode);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        URL url = new URL("http://util.krispot.com/util/SecurityImage.jpg?secutiryCode=" + secutiryCode);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setDoInput(true);
            BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
            for(int i = bis.read(); i > -1;i = bis.read()) {
                baos.write(i);
            }
        BufferedOutputStream bos = new BufferedOutputStream(resp.getOutputStream());
        bos.write(baos.toByteArray());
        bos.close();

Thank you, Navdeep Singh

Upvotes: 0

Jaime Ivan Cervantes
Jaime Ivan Cervantes

Reputation: 3697

I would suggest using a third-party service like reCaptcha, but in case you really need to provide your own implementation, you could use the recently introduced Matplotlib for GAE+Python to generate your own images.

Matplotlib is a plotting library for Python, and was recently introduced as part of GAE on December of 2012. You can use Matplotlib to render text as shown in this example. If you have aesthetic constraints on your captcha, you can render very fancy text and numbers with Matplotlib. Look at this example.

Upvotes: 1

Drew Sears
Drew Sears

Reputation: 12838

Generally, you can't.

The Image API is designed for transforming existing images, not generating new ones.

Theoretically if you found a pure Python image creation library it would run on App Engine, but it would be slow.

Why not just leverage an external CAPTCHA service?

Upvotes: 2

Alois Cochard
Alois Cochard

Reputation: 9862

Instead of creating your own impl. I recommend using a reliable service like reCaptcha: http://www.google.com/recaptcha

Upvotes: 1

Related Questions