Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
bo li
How to implement captcha in 6.0 EE?
March 26, 2012 10:05 PM
Answer

bo li

Rank: Junior Member

Posts: 34

Join Date: November 14, 2011

Recent Posts

Anyone can gieve a solution about How to implement captcha in 6.0 EE?

Thanks!
Danial Mustofa Habibi
RE: How to implement captcha in 6.0 EE?
March 26, 2012 10:10 PM
Answer

Danial Mustofa Habibi

Rank: Regular Member

Posts: 141

Join Date: November 1, 2011

Recent Posts

bo li:
Anyone can gieve a solution about How to implement captcha in 6.0 EE?

Thanks!



I'm never tried EE but in CE I'm using this method in my porlet class
 1@Override
 2    public void serveResource(ResourceRequest resourceRequest,
 3            ResourceResponse resourceResponse) throws IOException,
 4            PortletException {
 5        try {
 6            com.liferay.portal.kernel.captcha.CaptchaUtil.serveImage(
 7                    resourceRequest, resourceResponse);
 8        } catch (Exception e) {
 9            log.error(e);
10        }
11    }


and this one for validate the captcha
 1private static String getCaptchaValueFromSession(PortletSession session) {
 2        Enumeration<String> atNames = session.getAttributeNames();
 3        while (atNames.hasMoreElements()) {
 4            String name = atNames.nextElement();
 5            if (name.contains("CAPTCHA_TEXT")) {
 6                return (String) session.getAttribute(name);
 7            }
 8        }
 9        return null;
10    }


in your jsp just use this tag
1        <liferay-ui:error key="Invalid-captcha" message="Invalid-captcha"></liferay-ui:error>
2            <portlet:resourceURL var="captchaURL" />
3            <liferay-ui:captcha url="<%= captchaURL %>" />

if you want to use google captcha , go to control panel then to server administration -->catcha

regards

Danial