开发者

Captcha With Google AppEngine

I have a website where i want to put a custom made captcha, can't use online captcha service开发者_开发问答s 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?


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.


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?


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜