您的位置:首页 > 其它

How to add the CAPTCHA functionality in salesforce

2014-11-04 18:09 627 查看
A CAPTCHA (an acronym for “Completely Automated Public Turing test to tell Computers and Humans Apart”) is a type of challenge-response
test used in computing to determine whether or not the user is human. It uses the popular reCAPTCHA technology to implement the challenge.

There are times when we need to prevent the spam or garbage data filled by any anonymous then we need to use reCAPTCHA functionality. The reCAPTCHA looks like:





It contains random distorted images that is easily read by any human being.

We can use this in salesforce site etc. Lets take an example,a company provide a form for Enquiry, and if they needs protection from abuse, it is recommended that they use a reCAPTCHA. With this they ensure that a human was filling in a form before creating
a new request for them.

Here I am providing steps to use reCAPTCHA in salesforce :

Step 1 – First we need to get public and private key from the reCAPTCHA site to access this functionality.First we need to sign
up for a CAPTCHA key . After signing up we redirect to the “Create a reCAPTCHA key” page and here you need to enter domail URL and check the “Enable this key on all domains (global key)” option to make it global key which is used by any domain and create
keys .To proceed this way you got your public and private key which is further used in apex and VF page.

Step 2 – Now you need to add at remote site setting by which salesforce can invoke code from that particular site.

Go to the Setup -> Security Controls -> Remote Site Settings. And add the following URL :https://www.google.com.



Step
3- Now you have reCAPTCHA key as well as you added remote site settings. At last you need to write down code to achieve the reCAPTCHA functionality.

Apex Code :

In the above code we need to make a HTTP post with challenge,response ,private key as a parameter to reCAPTCHA site in the “verifyAndSubmit” method and the response body contains ‘true’ if the challenge and response is equal otherwise contain false.

And the Visual force page code is:

In the VF we need to pass public key to create reCAPTCHA.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: