+ Start a Discussion
Prabhat Singh 56Prabhat Singh 56 

Captcha for Lightning

Hello team,

we are implementing a community based on Lightning components: we would like to know if it is possible to implement Captcha on a Lightning component like what can be done on Visualforce.

Please suggest me the best and please share with me the document.

Rajiv Penagonda 12Rajiv Penagonda 12
Hi Prabhat, because of javascript restrictions in Lightning components, it may not be an easy job.

I am not sure if you are still having this challenge. I am adding my thoughts for reference:

The solution to this can be built by using two guides which Salesforce provides
1. Adding CAPTCHA to force.com sites link here (https://developer.salesforce.com/page/Adding_CAPTCHA_to_Force.com_Sites). This document explains how to implement CAPTCHA in a visual force page.
2. Embedding a VF page in a Lightning component. Link here (https://developer.salesforce.com/blogs/developer-relations/2017/01/lightning-visualforce-communication.html). This document explains how to embed a VF page in Lightning component and how to communicate between the two.

The soution at a very high level is as follows:
1. Implement CAPTCHA in a VF page as per above guide.
2. Disable sidebar and header of the VF page
3. Enable the VF page for all profiles and add it to your site (to enable for guest user). This makes the VF page public.
4. Embed the VF page in your lightning component within an iframe as per guide above.
5. Make the iframe borderless.
6. Communicate status between the VF page and Lightning component through parent.postMessage javascript API.
7. When VF page indicates to the Lightning component that CAPTCHA has been verified, fire an Application event from your lightning component to announce that user has completed CAPTCHA and take action accordingly in same/other components.

Hope this helps. If this solves your query, do mark this as solution.