CAPTCHA program in java applet

CAPTCHA is challenge response test most often placed within form to determine that the user is a human being and not a machine. CAPTCHA is a form of access control.A CAPTCHA images shows a random string which user has to type to submit a form. CAPTCHA generates and grades the test that human can pass but current computer program cannot.since computers are assumed to be unable to solve CAPTCHA,any user entering a correct format is presumed to be human. CAPTCHA are mainly used by websites that offers services like online polls and registration forms.

How TO Run

Create exp.java file and paste code below in it.
you need four images with file name as moiates,plings,pritio,tibra
run program in applet viewer.
run applet in applet viewer
run applet in browser

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
*/
public class exp extends Applet implements ActionListener
{
String msg;
Button submit,change;
TextField nameField;
Image img1;
String filenames[]={"Image1","Image2","Image3","Image1"};
String filetext[]={"moiates","plings","pritio","tibra"};
String filename;
int x;
public void init()
{
setLayout(null);
nameField = new TextField("",5);
submit = new Button("Submit");
add(nameField);
add(submit);
submit.addActionListener(this);
filename=new String(filenames[0]);
img1 = getImage(getDocumentBase(), getParameter(filename));
nameField.setBounds(100,150,100,30);
submit.setBounds(100,200,100,40);
}
public void actionPerformed(ActionEvent ae)
{
String str=nameField.getText();
if(str.equals(filetext[x]))
{
msg="LOG IN";
repaint();
}
else
{
msg="WRONG TRY AGAIN";

x=(int)((Math.random()*100)%4);
filename=new String(filenames[x]);
img1 = getImage(getDocumentBase(), getParameter(filename));
repaint();
}
}

public void paint(Graphics g)
{
g.drawImage(img1, 10,10,this);
g.drawString(msg,100,300);
}
}

captcha program in java OUTPUT:

CAPTCHA

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *