Web applications might often need captcha in order to prevent application from robotic attacks. Following example demonstrates how to build custom captcha in ADF Technology
Display Captcha :
Add following in jspx:
<af:panelGroupLayout id="pgld11" layout="horizontal">
<af:outputLabel value="#{pageFlowScope.backingBean.secretQ}" id="otd14"
inlineStyle="font-weight:normal; font-size:small; color:Black; font-family:Arial;"/>
<af:spacer width="18" height="5" id="sd13"/>
<af:inputText simple="true" label="secretQ" id="it7capta" contentStyle="width:100px; height:22px; font-family:Arial; font-size:small; color:Black; border-color:#878787;"
value="#{pageFlowScope.backingBean.secretUA}"
autoSubmit="true"
binding="#{pageFlowScope.backingBean.secreatAnswer_binding}">
</af:inputText>
</af:panelGroupLayout>
in backing bean define the variables as:
private String secretQ, secretA, secretUA;
public void setSecretQ(String secretQ) {
this.secretQ = secretQ;
}
public String getSecretQ() {
List<String> secretQandA = CAPTCHAUtil.getQuestionAndAnswer();
this.setSecretQ(secretQandA.get(0));
this.setSecretA(secretQandA.get(1));
this.setSecretUA("");
return secretQ;
}
public void setSecretA(String secretA) {
this.secretA = secretA;
}
public String getSecretA() {
return secretA;
}
public void setSecretUA(String secretUA) {
this.secretUA = secretUA;
}
public String getSecretUA() {
return secretUA;
}
please find the captcha util class attached. it can be modified as per user needs.
Validate Captcha:
Call this method to validate captcha:
private Boolean validateCapta() {
if(getSecretUA()== null){
retValue=false;
}else{
if(getSecretUA().equals("")){
retValue=false;
}else if(!getSecretA().equalsIgnoreCase(getSecretUA())){
retValue=false;
}
}
return retValue;
}
Display Captcha :
Add following in jspx:
<af:panelGroupLayout id="pgld11" layout="horizontal">
<af:outputLabel value="#{pageFlowScope.backingBean.secretQ}" id="otd14"
inlineStyle="font-weight:normal; font-size:small; color:Black; font-family:Arial;"/>
<af:spacer width="18" height="5" id="sd13"/>
<af:inputText simple="true" label="secretQ" id="it7capta" contentStyle="width:100px; height:22px; font-family:Arial; font-size:small; color:Black; border-color:#878787;"
value="#{pageFlowScope.backingBean.secretUA}"
autoSubmit="true"
binding="#{pageFlowScope.backingBean.secreatAnswer_binding}">
</af:inputText>
</af:panelGroupLayout>
in backing bean define the variables as:
private String secretQ, secretA, secretUA;
public void setSecretQ(String secretQ) {
this.secretQ = secretQ;
}
public String getSecretQ() {
List<String> secretQandA = CAPTCHAUtil.getQuestionAndAnswer();
this.setSecretQ(secretQandA.get(0));
this.setSecretA(secretQandA.get(1));
this.setSecretUA("");
return secretQ;
}
public void setSecretA(String secretA) {
this.secretA = secretA;
}
public String getSecretA() {
return secretA;
}
public void setSecretUA(String secretUA) {
this.secretUA = secretUA;
}
public String getSecretUA() {
return secretUA;
}
please find the captcha util class attached. it can be modified as per user needs.
Validate Captcha:
Call this method to validate captcha:
private Boolean validateCapta() {
if(getSecretUA()== null){
retValue=false;
}else{
if(getSecretUA().equals("")){
retValue=false;
}else if(!getSecretA().equalsIgnoreCase(getSecretUA())){
retValue=false;
}
}
return retValue;
}