53
Table of Contents Introduction..................................2 Diagram.......................................3 Use Case........................................... 3 Class Diagram...................................... 4 Sequence Diagram................................... 5 Admin Registration........................................5 User Registration.........................................6 Login..................................................... 6 Flow Chart Diagram................................. 7 Screen Shot...................................8 Reference....................................12 Appendix A: Source Code......................13

Fingerprint Documentation

  • Upload
    hen-dry

  • View
    100

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Fingerprint Documentation

Table of Contents

Introduction.........................................................................................2

Diagram................................................................................................3

Use Case............................................................................................................3

Class Diagram...................................................................................................4

Sequence Diagram............................................................................................5

Admin Registration...........................................................................................................5

User Registration...............................................................................................................6

Login...................................................................................................................................6

Flow Chart Diagram........................................................................................7

Screen Shot..........................................................................................8

Reference............................................................................................12

Appendix A: Source Code................................................................13

Page 2: Fingerprint Documentation

Introduction

Biometric Login System is an application developed using Java Programming Language and

Fingerprint SDK supported by GrFinger1, this application is used to prevent any unauthorized

parties to gain access to the system by using dual-layer of security protection which are

username combined with password at the first layer and Fingerprint verification at the second

layer.

This application also protect user’s confidential data such as username and password from key

Logger software which has capability of recording key stroke from keyboard, by

implementing OSK (On-Screen Keyboard) user can enter their user name & password via

virtual keyboard instead of “real” keyboard. MD5 Encryption is also being used to encrypt

password which are stored in the database.

During the development of this application, we’ve been using 3-tier architecture programming

(K.,Channu, N.D.) concept to ensure user cannot directly connect to the database, but they can

only connect via controller as the middle-man. This concept can improve security of the

application, easy of future enhancement and more robust program.

Out of the common functionalities, some additional functions such as ability to delete current

account, register new administrator only by administrator, register new account, and analog

clock feature were also implemented in the application to enhance user’s look-and-feel

experience.

1 http://www.grfinger.com/

Page 3: Fingerprint Documentation

Diagram

Use Case

Page 4: Fingerprint Documentation

Class Diagram

Page 5: Fingerprint Documentation

Sequence Diagram

Admin Registration

Page 6: Fingerprint Documentation

User Registration

Login

Page 7: Fingerprint Documentation

Flow Chart Diagram

Page 8: Fingerprint Documentation

Screen Shot

MAIN SCREENThis is main screen of the application, user can choose to login or register for new account. User also can select their status as Administrator or Normal User.

LOGINAfter their user name and password match, this screen will be shown to user as information.

Page 9: Fingerprint Documentation

Fingerprint ScanScan button is used to open image from file which contains fingerprint images, and after fingerprint image loaded to the panel, it’ll auto-extract until user press Login button for verification

Login Successful information after user passes both layer of protection, and user’s information will be retrieved from database and shown to user.

Page 10: Fingerprint Documentation

Registration formThis form is use to register new account for Administrator

Registration ValidationThis message will pop out if the user name entered is already stored in database to prevent duplicated data and also invalid password verification error message to ensure the password is matched with the re-enter password.

Page 11: Fingerprint Documentation

On-Screen Keyboard Built in OSK from windows to prevent data stolen by key logger malware

About Box

Page 12: Fingerprint Documentation

References

Deitel, HM, Deitel, PJ 2004, Java™ How to Program, 6edn, Prentice

Hall,USA.

Anon, “Message Digest Algorithm 5 (MD5) “, viewed at 01 October 2010,

< http://en.wikipedia.org/wiki/MD5 >

Anon, “MySQL Documentation”, viewed at 28 September 2010,

< http://dev.mysql.com/doc/refman/5.1/en/tutorial.html >

Liang,Daniel 2005, Introduction to Java Programming comprehensive version,5

edn,Prentice Hall,USA.

Kambalyal ,Channu N.D., “3-tier architecture”, US.

guestd0cc01, “3-tier Architecture” , viewed at 01 October 2010

< http://www.slideshare.net/guestd0cc01/3-tier-architecture >

Page 13: Fingerprint Documentation

Appendix A: Source Code

Login.java Classpackage Interface;

/** * * @author Mr. Hendry */import System.*;import com.griaule.grFinger.FingerprintTemplate;import java.awt.*;import java.awt.event.*;import java.awt.image.ImageProducer;import java.io.IOException;import java.sql.SQLException;import java.util.Calendar;import java.util.GregorianCalendar;import javax.swing.*;import javax.swing.filechooser.FileNameExtensionFilter;

public class Login extends JFrame implements ActionListener{ //------ Declaration for fingerprint --------- private JFileChooser chooser = new JFileChooser(); private int score; private Controller controller; private final int RESOLUTION = 300; private Fingerprint fingerprint = new Fingerprint(); private Image image; private FingerprintTemplate template; private int time = 0;

private Timer scanTimer = new Timer ( 50 , this ); private int w = 400; private JPanel panelFinger, panelBiometric; private static int attemp = 0 , attempF = 0; private String password; private JMenu menuFile; private JMenuItem menuRegister, menuExit, menuAbout; private JComboBox cmbUserType; private JPanel upPanel, panelMain; private JLabel lblWelcome, lblInformation, lblLogin , lblUser,lblPass;

Page 14: Fingerprint Documentation

private JLabel imgUCTI; private JTextField txtUser; private JPasswordField txtPass; private JButton btnLogin ,btnCancel, btnOSK, btnSign, btnReset, btnBrowse; private JProgressBar proBar; private Clock myClock; private Timer timer = new Timer(1000, (this)); private Timer tmrScreen = new Timer (1 , (this)); private Timer tmrClose = new Timer (10 , (this));

public static void main(String[] args ) { Login app = new Login(); app.setSize ( 400 , 660); app.setLogin(app); }

private void setLogin ( Login log ) { fingerprint.setLogin(log); }

public Login() { this.setTitle("Login Screen"); this.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE); this.setVisible ( true); this.setLayout (null); fingerprint.start();

Container cp ; cp = this.getContentPane(); cp.setBackground(Color.white);

//----- Setting Components ( JLabel , JButton ) ------- lblInformation = new JLabel(); lblInformation.setBounds ( 450 , 10 , 500 , 50 ); lblWelcome = new JLabel ("WELCOME!"); lblWelcome.setFont(new Font ( "Magneto Bold" , Font.BOLD , 35)); lblUser = new JLabel ("User Name : "); lblPass = new JLabel ("Password : "); lblLogin = new JLabel("Login as : "); txtUser = new JTextField (15 ); txtPass = new JPasswordField (15); btnSign = new JButton ( "Login"); btnSign.setBounds ( 75 , 510 , 100 , 30 ); btnReset = new JButton ( "Reset"); btnReset.setBounds ( 200 , 510 , 100 , 30); btnLogin = new JButton("Login"); btnLogin.setBounds ( 520 , 510 , 100 , 30); btnCancel = new JButton("Cancel"); btnCancel.setBounds ( 645 , 510 , 100 , 30); btnOSK = new JButton (""); btnOSK.setIcon ( new ImageIcon ( getClass().getResource("Image/OSK.gif"))); btnOSK.setBounds ( 332 , 390 , 30 , 25 ); btnBrowse = new JButton ("Scan"); btnBrowse.setBounds ( 450 , 70 , 90 , 25);

Page 15: Fingerprint Documentation

proBar = new JProgressBar (); proBar.setBounds ( 550 , 70 , 280 , 25); proBar.setStringPainted(true); String userType[] = {"USER" , "ADMINISTRATOR "}; cmbUserType = new JComboBox (userType); menuAbout = new JMenuItem("About"); menuFile = new JMenu("File"); menuRegister = new JMenuItem ( "Register User"); menuExit = new JMenuItem ("Exit"); menuFile.add(menuRegister); menuFile.addSeparator(); menuFile.add(menuAbout); menuFile.add(menuExit); JMenuBar bar = new JMenuBar(); bar.add(menuFile);

//-------- Setting UCTI Icon ------- Icon UCTI = new ImageIcon ( getClass().getResource( "Image/UCTI.gif")); imgUCTI = new JLabel(UCTI);

//------- CLOCK/TIME Setting ------- myClock = new Clock(); timer.start(); timer.addActionListener ( new ActionListener() { public void actionPerformed (ActionEvent e ) { Calendar myCalendar = new GregorianCalendar(); myClock.setHour(myCalendar.get(Calendar.HOUR)); myClock.setMinute(myCalendar.get(Calendar.MINUTE)); myClock.setSecond ( myCalendar.get(Calendar.SECOND)); } }); myClock.setBounds ( 155 , 150 , 70, 70);

//----------- UPPER PANEL ( contains image & welcome ) Setting ---------- upPanel = new JPanel(); upPanel.setBackground(Color.white); upPanel.setBounds ( 15 , 0 , 350, 315); upPanel.setLayout ( new FlowLayout(FlowLayout.CENTER , 0 , 15)); upPanel.add(lblWelcome); upPanel.add(imgUCTI);

panelMain = new JPanel(); panelMain.setLayout(new FlowLayout(FlowLayout.CENTER, 20,20)); panelMain.setBounds ( 25 , 330 , 340 , 150); panelMain.setBackground(Color.white); panelMain.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); panelMain.add(lblUser); panelMain.add(txtUser); panelMain.add(lblPass); panelMain.add(txtPass); panelMain.add(lblLogin); panelMain.add(cmbUserType);

panelFinger = new JPanel(); //panel to store fingerprint image

Page 16: Fingerprint Documentation

panelFinger.setBorder ( BorderFactory.createLineBorder(Color.BLACK)); panelFinger.setBounds ( 0 , 0 , 380 , 380);

panelBiometric = new JPanel(); panelBiometric.setLayout ( null); panelBiometric.setBounds ( 450 , 100 , 380 ,380); panelBiometric.add(panelFinger);

//--------- Register Event-Handing --------- menuAbout.addActionListener(this); btnOSK.addActionListener (this); btnReset.addActionListener ( this); btnSign.addActionListener(this); btnBrowse.addActionListener(this); btnLogin.addActionListener(this); btnCancel.addActionListener (this); menuRegister.addActionListener ( this ); btnSign.addKeyListener( new keyHandler()); menuExit.addActionListener (this); this.add(lblInformation); this.add(btnLogin); this.add(btnCancel); this.add(btnBrowse); this.add(proBar); this.setJMenuBar(bar); this.add(btnReset); this.add(btnSign); this.add(btnOSK); this.add(upPanel); this.add(panelMain); this.add(myClock); this.add(panelBiometric); } public void actionPerformed ( ActionEvent e ) { if ( e.getSource() == menuExit ) { JOptionPane.showMessageDialog(null, "Good Bye!"); System.exit(0); } if ( e.getSource() == menuRegister ) { Register register = new Register (1 , fingerprint ); fingerprint.setRegister(register); } if ( e.getSource() == menuAbout) { new About(); } if ( e.getSource() == tmrScreen) { if ( this.getWidth() < 860) { w += 2; this.setSize( w , 660); } else

Page 17: Fingerprint Documentation

{ tmrScreen.stop(); w = 400; } } if ( e.getSource() == scanTimer ) { time ++; if ( time >= 100 ) { time = 0; scanTimer.stop(); proBar.setValue(0); fingerprint.loadImage ( chooser.getSelectedFile().getAbsolutePath() , RESOLUTION ); setTemplate ( fingerprint.getTemplate() ); } else proBar.setValue(time); } if ( e.getSource() == btnBrowse ) { panelFinger.repaint(); FileNameExtensionFilter myFilter = new FileNameExtensionFilter ( "Fingerprint" , "bmp"); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileFilter ( myFilter);

if ( chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) scanTimer.start(); }

if ( e.getSource() == tmrClose) { if ( this.getWidth() > 400) { w -= 2; this.setSize( w , 660); } else { tmrClose.stop(); w = 400; btnSign.setVisible(true); btnReset.setVisible(true); txtUser.setEnabled(true); txtPass.setEnabled(true); cmbUserType.setEnabled(true); } }

if ( e.getSource() == btnCancel) { btnReset.doClick(); w = 860; tmrClose.start(); }

//btnLogin to check fingerprint (Layer 2)

Page 18: Fingerprint Documentation

if ( e.getSource() == btnLogin) { int personStatus; if (cmbUserType.getSelectedIndex() == 0 ) personStatus = 1; else personStatus = 0;

String userName = txtUser.getText(); boolean fingerStatus = fingerprint.verify ( txtUser.getText() , getTemplate() , personStatus); System.out.println("finger : " + fingerStatus);

if ( fingerStatus == true ) { JOptionPane.showMessageDialog(null, "Login succesfully!! \n\n" + "Fingerprint matched score = " + score);

if ( personStatus == 0 ) showAdminData( 0 , controller, userName ); else showUserData( 1, controller, userName ); } else { panelFinger.repaint(); txtUser.setText(""); txtPass.setText(""); txtUser.requestFocusInWindow(); attempF++;

if ( attempF >= 3 ) { JOptionPane.showMessageDialog ( null , "Sorry you've Scanned wrong Fingerprint for 3 times\n\nProgram will be terminated." , "Invalid Fingerprint" , JOptionPane.ERROR_MESSAGE); System.exit(0); } else JOptionPane.showMessageDialog(null,"Fingerprint denied , Wrong : " + attempF + " x" + "\n\n Fingerprint matched score : " + score); } }

//btnSign to check UserName and Password (Layer1 Authentication) if ( e.getSource() == btnSign ) { if ( Validator.validateLogin ( txtUser.getText() , txtPass.getPassword() )) { int personStatus; if (cmbUserType.getSelectedIndex() == 0 ) personStatus = 1; else personStatus = 0;

controller = new Controller ( personStatus ); password = new String ( txtPass.getPassword()); try

Page 19: Fingerprint Documentation

{ String userName = txtUser.getText(); boolean loginStatus = controller.login ( userName , password); System.out.println("pass : " + loginStatus);

if ( loginStatus == true ) { JOptionPane.showMessageDialog(null, "welcome " + controller.getUserName(personStatus,userName) + "\n\nPlease Scan your Fingerprint"); lblInformation.setText("Welcome " + controller.getUserName(personStatus, userName) + "! You signed in as " + ((personStatus == 0) ? "Administrator" : "Normal User")); btnSign.setVisible(false); btnReset.setVisible(false); txtUser.setEnabled(false); txtPass.setEnabled(false); cmbUserType.setEnabled(false); w = 400; tmrScreen.start(); } else { txtUser.setText(""); txtPass.setText(""); txtUser.requestFocusInWindow(); attemp++;

if ( attemp >= 3 ) { JOptionPane.showMessageDialog ( null , "Sorry you've entered wrong user name and password for 3 times\n\nProgram will be terminated." , "Invalid User Name and Password" , JOptionPane.ERROR_MESSAGE); System.exit(0); } else JOptionPane.showMessageDialog(null,"User Name and Password doesn't match , Wrong : " + attemp + " x" ); } } catch ( IOException ex1) { ex1.printStackTrace();} catch ( SQLException ex2) {ex2.printStackTrace();} } }

if ( e.getSource() == btnOSK ) { txtPass.requestFocusInWindow(); try { Runtime rt = Runtime.getRuntime(); Process pr = rt.exec("C:/Windows/system32/osk.exe"); } catch( IOException ex) { System.out.println(ex.toString()); ex.printStackTrace(); } }

Page 20: Fingerprint Documentation

if ( e.getSource() == btnReset ) { txtPass.setText(""); txtUser.setText(""); cmbUserType.setSelectedIndex(0); } }

//--------- Enable "ENTER" as btnOK click ----------- public class keyHandler extends KeyAdapter { @Override public void keyPressed ( KeyEvent e ) { int key = e.getKeyCode(); if ( key == KeyEvent.VK_ENTER) { btnSign.doClick(); } } }

//************* SHOW DATA AFTER SUCCESSFUL LOGIN ************* public void showUserData (int status, Controller controller, String userName ) { Object[] data = new Object[4]; data = controller.getUserData( status, userName );

int option = JOptionPane.showOptionDialog(null,"Your Data :\n\n" + "Unique ID : " + data[0].toString() + "\n\n" + "First Name : " + data[1].toString() + "\n\n" + "Last Name : " + data[2].toString() + "\n\n" + "Gender : " + data[3].toString() + "\n\n" ,"USER DATA", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new String[]{ "Delete" , "Log Out"}, null);

switch (option) { case 0 : int opt = JOptionPane.showConfirmDialog(null, "Are you sure ? " , "Confirmation" , JOptionPane.YES_NO_OPTION); if ( opt == JOptionPane.YES_OPTION ) controller.delete (Integer.parseInt(data[0].toString())); startNewSession(); break; case 1 : startNewSession(); break; }

}

public void showAdminData ( int status, Controller controller, String userName ) { Object[] data = new Object[4]; data = controller.getUserData( status, userName );

int option = JOptionPane.showOptionDialog(null,"Your Data :\n\n" +

Page 21: Fingerprint Documentation

"Unique ID : " + data[0].toString() + "\n\n" + "First Name : " + data[1].toString() + "\n\n" + "Last Name : " + data[2].toString() + "\n\n" + "Gender : " + data[3].toString() + "\n\n" ,"ADMINISTRATOR DATA", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new String[]{"Add New Admin", "Delete" , "Log Out"}, null);

switch (option) { case 0 : Register register = new Register ( 0 , fingerprint); fingerprint.setRegister(register); startNewSession(); break; case 1 : int opt = JOptionPane.showConfirmDialog(null, "Are you sure ? " , "Confirmation" , JOptionPane.YES_NO_OPTION); if ( opt == JOptionPane.YES_OPTION ) { if ( Integer.parseInt ( data[0].toString()) == 1 ) JOptionPane.showMessageDialog(null, "Sorry the first Admin can't be deleted!"); else { controller.delete (Integer.parseInt(data[0].toString())); startNewSession(); } } break; case 2 : startNewSession(); break; } }

private void startNewSession() { btnCancel.doClick(); btnReset.doClick(); attemp = 0; attempF = 0 ; }

//******************* FINGERPRINT EVENT-HANDLING ******************** public void showImage(ImageProducer producer) { image = panelFinger.createImage(producer); panelFinger.getGraphics().drawImage(image,0,0,panelFinger.getWidth(),panelFinger.getHeight(),null); }

public void setTemplate ( FingerprintTemplate template ) { this.template = template; }

public FingerprintTemplate getTemplate () {

Page 22: Fingerprint Documentation

return template; } public void setScore ( int score ) { this.score = score; }}

Register.java classpackage Interface;

/** * * @author Mr. Hendry */

import System.Controller;import System.Fingerprint;import System.Validator;import com.griaule.grFinger.FingerprintTemplate;import java.awt.*;import java.awt.event.*;import java.awt.image.ImageProducer;import java.util.Vector;import javax.swing.*;import javax.swing.border.BevelBorder;import javax.swing.filechooser.FileNameExtensionFilter;

public class Register extends JFrame implements ActionListener,FocusListener{ //------------ Declaration for Fingerprint-------------- Fingerprint fingerprint; FingerprintTemplate template; Controller controller;

//------------ Variable Declaration ----------------- JFileChooser chooser = new JFileChooser(); private Image image; private final int RESOLUTION = 300; private static int peopleStatus ; private Vector<Object> objInput = new Vector<Object>(); private int proValue; private String status; private JRadioButton radMale , radFemale ; private ButtonGroup btnGroup = new ButtonGroup(); private JLabel lblFirstName, lblLastName, lblUserName , lblPass , lblVerifyPass , lblGood , lblBad; private JTextField txtFirstName , txtLastName , txtUserName ; private JPasswordField txtPass , txtVerifyPass; private JButton btnRegister, btnCancel , btnBrowse; private JPanel normalPanel , securePanel , panelFinger , genderPanel , enrollPanel; private JProgressBar proBar , scanBar; private Timer scanTimer = new Timer ( 50 , this ); private int time = 0;

public Register ( int status , Fingerprint fingerprint ) {

Page 23: Fingerprint Documentation

//---------Assigning fingerprint --------- this.fingerprint = fingerprint;

//------------ Determine Status of Login (Admin or User) ---------- peopleStatus = status; this.status = ( status == 0 ) ? "Administrator" : "User";

//---------- Frame Setting ----------- this.setTitle ( this.status + " Registration Form"); this.setSize (860 , 600); this.setVisible(true); this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); this.setLayout(null); this.setResizable(false);

// -------- Components ( JLabel , JTextField , JButton , JProgressBar ) Setting ------------- lblFirstName = new JLabel ("First Name : "); lblLastName = new JLabel ("Last Name : "); lblUserName = new JLabel (" User Name : "); lblPass = new JLabel (" Password : "); lblVerifyPass = new JLabel ("Re-enter Password : ");

txtFirstName = new JTextField (13); txtLastName = new JTextField (13); txtUserName = new JTextField ( 13); txtPass = new JPasswordField ( 13 ); txtVerifyPass = new JPasswordField ( 13 );

scanBar = new JProgressBar (); scanBar.setStringPainted(true); scanBar.setBorderPainted(true); scanBar.setBounds ( 130 , 20 , 280 , 25);

btnRegister = new JButton ("Register"); btnRegister.setBounds ( 350 , 515 , 100 , 30 ); btnCancel = new JButton ("Cancel"); btnCancel.setBounds ( 470 , 515 , 100 , 30); btnBrowse = new JButton ("Scan"); btnBrowse.setBounds ( 20 , 20 , 90 , 25 );

proBar = new JProgressBar (0); proBar.setMaximum(100); proBar.setValue (0); proBar.setBorderPainted(true); proBar.setVisible(true); proBar.setPreferredSize(new Dimension ( 230 , 20));

//-------- Icon ( Strong or week password image ) setting -------------- lblBad = new JLabel (); lblBad.setIcon ( new ImageIcon ( getClass().getResource ( "Image/Bad.png"))); lblGood = new JLabel(); lblGood.setIcon ( new ImageIcon ( getClass().getResource ( "Image/Good.gif")));

//--------------------- JRadioButton setting ---------------- radFemale = new JRadioButton ( "Female"); radMale = new JRadioButton ( "Male"); radMale.setSelected(true);

Page 24: Fingerprint Documentation

btnGroup.add(radFemale); btnGroup.add(radMale);

//------------ PANEL setting ---------------- genderPanel = new JPanel( new FlowLayout(FlowLayout.LEFT)); genderPanel.add(radMale); genderPanel.add(radFemale); genderPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); genderPanel.setBorder(BorderFactory.createTitledBorder("Gender"));

normalPanel = new JPanel(); normalPanel.setLayout ( new FlowLayout( FlowLayout.CENTER , 20 , 20)); normalPanel.setBorder( BorderFactory.createBevelBorder(BevelBorder.RAISED)); normalPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); normalPanel.setBorder( BorderFactory.createTitledBorder(this.status + " Personal Info")); normalPanel.setBounds ( 20 , 20 , 350 ,230 ); normalPanel.add(lblFirstName); normalPanel.add(txtFirstName); normalPanel.add(lblLastName); normalPanel.add(txtLastName); normalPanel.add(genderPanel);

panelFinger = new JPanel(); panelFinger.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED , Color.lightGray, Color.lightGray)); panelFinger.setBounds ( 24 , 55 , 380 , 400 );

securePanel = new JPanel(); securePanel.setBorder ( BorderFactory.createTitledBorder("User Name & Password")); securePanel.setBounds ( 20 , 280 , 353 , 220); securePanel.setLayout ( new FlowLayout ( FlowLayout.CENTER , 20 , 20)); securePanel.add(lblUserName); securePanel.add(txtUserName); securePanel.add(lblPass); securePanel.add(txtPass); securePanel.add(lblVerifyPass); securePanel.add(txtVerifyPass); securePanel.add(lblBad); securePanel.add(proBar); securePanel.add(lblGood);

enrollPanel = new JPanel(); enrollPanel.setBounds ( 400 , 20 , 430 , 479); enrollPanel.setBorder ( BorderFactory.createTitledBorder(this.status + " Fingerprint enroll")); enrollPanel.setLayout ( null); enrollPanel.add(btnBrowse); enrollPanel.add(scanBar); enrollPanel.add(panelFinger);

//------- EVENT HANDLING ----------------- txtPass.addKeyListener( new KeyHandler()); txtVerifyPass.addFocusListener(this); btnRegister.addActionListener(this); txtUserName.addFocusListener(this); btnCancel.addActionListener(this); btnBrowse.addActionListener (this); this.add(normalPanel);

Page 25: Fingerprint Documentation

this.add(securePanel); this.add(enrollPanel); this.add(btnRegister); this.add(btnCancel); }

//------------Button Event-Handling public void actionPerformed (ActionEvent e) { if ( e.getSource() == btnRegister ) { String gender = (radMale.isSelected()) ? "Male" : "Female"; objInput.add(txtFirstName.getText()); objInput.add(txtLastName.getText()); objInput.add(txtUserName.getText()); objInput.add(new String(txtPass.getPassword())); objInput.add(new String(txtVerifyPass.getPassword())); objInput.add(proBar.getValue());

if (Validator.validateInput(objInput)) { objInput.clear(); objInput.add(txtFirstName.getText()); objInput.add(txtLastName.getText()); objInput.add(gender); objInput.add(txtUserName.getText()); objInput.add(txtPass.getPassword()); objInput.add(getTemplate());

controller = new Controller( peopleStatus ); controller.register ( objInput ); fingerprint.setRegister(null); this.dispose(); } else { objInput.clear(); } } if ( e.getSource() == btnCancel ) { int data = JOptionPane.showConfirmDialog(null, "Are you sure ? " , "Confirmation" , JOptionPane.YES_NO_OPTION); if ( data == JOptionPane.YES_OPTION ) { fingerprint.setRegister(null); this.dispose(); } }

if ( e.getSource() == btnBrowse ) { panelFinger.repaint();

FileNameExtensionFilter myFilter = new FileNameExtensionFilter ( "Fingerprint" , "bmp"); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileFilter ( myFilter);

Page 26: Fingerprint Documentation

if ( chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) scanTimer.start(); } if ( e.getSource() == scanTimer ) { time ++; if ( time >= 100) { scanTimer.stop(); time = 0 ; scanBar.setValue(0); fingerprint.loadImage ( chooser.getSelectedFile().getAbsolutePath() , RESOLUTION ); setTemplate ( fingerprint.getTemplate() ); } else scanBar.setValue(time); } }

//------------- Focus Event - Handling ------------ public void focusGained(FocusEvent e) { } public void focusLost(FocusEvent e) { if ( e.getSource() == txtVerifyPass) { String pass = new String ( txtPass.getPassword()); String verify = new String ( txtVerifyPass.getPassword()); if ( !(pass.equals(verify))) { JOptionPane.showMessageDialog(null, "Please Verify your Password Again." , "Invalid Password Verification" , JOptionPane.ERROR_MESSAGE); txtVerifyPass.setText(null); } } if ( e.getSource() == txtUserName ) { if ( !Validator.isAvailable(txtUserName.getText() , peopleStatus)) { JOptionPane.showMessageDialog ( null , "User Name : \"" + txtUserName.getText() + "\" already in Database\nPlease choose another User Name." , "Invalid UserName" , JOptionPane.ERROR_MESSAGE); txtUserName.setText(""); } } }

//--------------- Adapter class for Key event - Handling ------------ private class KeyHandler extends KeyAdapter { @Override public void keyReleased (KeyEvent e) { //to determine password Strength if (e.getSource() == txtPass) {

Page 27: Fingerprint Documentation

StringBuffer pass = new StringBuffer( new String (txtPass.getPassword())); switch (pass.length()) { case 0 : case 1: case 2: case 3: proValue = 0; break; case 4: proValue = 18; break; case 5: proValue = 30; break; case 6: proValue = 45; break; case 7: proValue = 60; break; case 8: proValue = 70; break; case 9: proValue = 80; break; case 10: case 30:proValue = 90; break; } if ( proValue >= 4 && Validator.isContainDigit ( pass)) proValue += 10;

if (proValue <= 100) proBar.setValue ( proValue); else proBar.setValue ( 100); } } }

//******************* FINGERPRINT EVENT-HANDLING ******************** public void showImage(ImageProducer producer) { image = panelFinger.createImage(producer); panelFinger.getGraphics().drawImage(image,0,0,panelFinger.getWidth(),panelFinger.getHeight(),null); }

public void setTemplate ( FingerprintTemplate template ) { this.template = template; }

public FingerprintTemplate getTemplate () { return template; }}

About.java Class/* * To change this template, choose Tools | Templates * and open the template in the editor. */

/* * About.java * * Created on Sep 26, 2010, 4:19:56 AM */

Page 28: Fingerprint Documentation

package Interface;

/** * * @author Mr. Hendry */public class About extends javax.swing.JDialog { /** A return status code - returned if Cancel button has been pressed */ public static final int RET_CANCEL = 0; /** A return status code - returned if OK button has been pressed */ public static final int RET_OK = 1;

/** Creates new form About */ public About() {

this.setResizable(false); this.addWindowListener(new java.awt.event.WindowAdapter() {

@Override public void windowClosing(java.awt.event.WindowEvent e) { dispose(); } }); this.setVisible(true); initComponents(); }

/** @return the return status of this dialog - one of RET_OK or RET_CANCEL */ public int getReturnStatus() { return returnStatus; }

/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {

jLayeredPane1 = new javax.swing.JLayeredPane(); jButton1 = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel();

addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { closeDialog(evt); } });

jButton1.setFont(new java.awt.Font("Castellar", 1, 12)); jButton1.setText("OK"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) {

Page 29: Fingerprint Documentation

jButton1ActionPerformed(evt); } }); jButton1.setBounds(150, 170, 90, 30); jLayeredPane1.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

jLabel2.setFont(new java.awt.Font("Tempus Sans ITC", 1, 48)); // NOI18N jLabel2.setText("Biometric System"); jLabel2.setBounds(0, 10, 396, 60); jLayeredPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N jLabel3.setText("By : Hendry Ang (TP020341)"); jLabel3.setBounds(40, 70, 310, 40); jLayeredPane1.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Interface/Image/hack2-1.gif"))); // NOI18N jLabel1.setBounds(0, 0, 400, 400); jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 403, javax.swing.GroupLayout.PREFERRED_SIZE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 403, javax.swing.GroupLayout.PREFERRED_SIZE) );

pack(); }// </editor-fold>

/** Closes the dialog */ private void closeDialog(java.awt.event.WindowEvent evt) { doClose(RET_CANCEL); }

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { dispose(); }

private void doClose(int retStatus) { returnStatus = retStatus; setVisible(false); dispose(); }

/** * @param args the command line arguments */

// Variables declaration - do not modify

Page 30: Fingerprint Documentation

private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLayeredPane jLayeredPane1; // End of variables declaration

private int returnStatus = RET_CANCEL;}

Clock.java class//Clock.java class is a class that contains panel with Analog Clock which is realtime//@Author Hendry

package Interface;import java.awt.*;import javax.swing.*;import java.util.*;

//clock ( analog and digital ) to show current time to userpublic class Clock extends JPanel{ private int hour; private int minute; private int second; public Clock() { this.setBackground(Color.WHITE); setCurrentTime(); } public Clock( int h , int m , int s ) { hour = h ; minute = m ; second = s ; } public void setHour ( int h ) { hour = h ; repaint(); } public int getHour () { return hour; }

public void setMinute ( int m ) { minute = m ; repaint(); } public int getMinute () { return minute; }

public void setSecond( int s ) { second = s; repaint(); } public int getSecond() { return second; }

Page 31: Fingerprint Documentation

// --------- Setting of appearence of the clock ( analog ) @Override protected void paintComponent ( Graphics graphic ) { super.paintComponent(graphic);

Graphics2D g = (Graphics2D) graphic;

int radius = 30;

int xCenter = getWidth() /2 ; int yCenter = getHeight()/2; g.setColor(Color.BLACK); g.fillRoundRect( xCenter - radius , yCenter-radius , 2 * radius , 2 * radius , 15, 15); g.setFont(new Font ( "Arial" , Font.BOLD , 10)); g.setColor(Color.WHITE); g.drawString ( "12" , xCenter - 5 , yCenter - radius + 12); g.drawString ("9" , xCenter - radius + 3 , yCenter + 5); g.drawString ( "3" , xCenter + radius - 10 , yCenter + 3 ); g.drawString ( "6" , xCenter - 3 , yCenter + radius - 3 );

//draw second hand int sLength = ( int ) (radius * 0.8 ); int xSecond = ( int ) (xCenter + sLength * Math.sin(second * ( 2 * Math.PI / 60))); int ySecond = ( int ) (yCenter - sLength * Math.cos ( second * ( 2 * Math.PI / 60))); g.setColor(Color.WHITE); g.setStroke( new BasicStroke( 2.0f ) ); g.drawLine ( xCenter , yCenter , xSecond , ySecond );

//draw minute hand int mLength = ( int ) (radius * 0.65); int xMinute = ( int ) (xCenter + mLength * Math.sin(minute * ( 2 * Math.PI /60))); int yMinute = ( int ) ( yCenter - mLength * Math.cos ( minute * ( 2 * Math.PI / 60))); g.setColor(Color.BLUE); g.setStroke( new BasicStroke(2.0f ) ); g.drawLine ( xCenter , yCenter , xMinute , yMinute);

//draw hour hand int hLength = ( int ) (radius * 0.5 ); int xHour = ( int ) (xCenter + hLength * Math.sin((hour % 12 + minute / 60.0) * ( 2 * Math.PI / 12))); int yHour = ( int ) (yCenter - hLength * Math.cos((hour % 12 + minute / 60.0) * ( 2 * Math.PI / 12))); g.setStroke( new BasicStroke(3.5f )); g.setColor(Color.GREEN); g.drawLine ( xCenter , yCenter , xHour , yHour); } public void setCurrentTime() { Calendar calendar = new GregorianCalendar(); this.hour = calendar.get(Calendar.HOUR_OF_DAY); this.minute = calendar.get(Calendar.MINUTE); this.second = calendar.get(Calendar.SECOND); }

Page 32: Fingerprint Documentation

@Override public Dimension getPreferredSize() { return new Dimension ( 150 , 150); }}

Controller.java classpackage System;/** * * @author Mr. Hendry */

import Storage.Database;import com.griaule.grFinger.FingerprintTemplate;import java.io.ByteArrayInputStream;import java.io.IOException;import java.math.BigInteger;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import java.sql.*;import java.util.Vector;import javax.swing.JOptionPane;

public class Controller{ private Object[] objOutput; private FingerprintTemplate template; private String encryptedPassword; private Database DB = new Database(); private PreparedStatement pStmt; private Connection conn; private String regQuery , logQuery, showQuery , delQuery ,updateQuery, nameQuery; private int personStatus;

public Controller ( int status ) { personStatus = status; if ( status == 0 ) { regQuery = "insert into admin (afName,alName,aGender,auName,aPass,aTemplate) values (?,?,?,?,MD5(?),?)"; logQuery = "select aPass from admin where auName =?"; nameQuery = "select afName,alName from admin where auName=?"; showQuery = "select adminID,afName,alName,aGender from admin where auName=?"; delQuery = "delete from admin where adminID=?"; updateQuery = "update admin set afName=?,alName=?,aGender=?,auName=?,aPass=MD5(?),aTemplate=? where adminID=?"; } else { regQuery= "insert into user (ufName,ulName,uGender,uuName,uPass,uTemplate) values (?,?,?,?,MD5(?),?)"; logQuery = "select uPass from user where uuName =?"; showQuery = "select userID,ufName,ulName,uGender from user where uuName=?"; nameQuery = "select ufName,ulName from user where uuName=?";

Page 33: Fingerprint Documentation

delQuery = "delete from user where userID=?"; updateQuery = "update user set ufName=?,ulName=?,uGender=?,uuName=?,uPass=MD5(?),uTemplate=? where userID=?"; } }

private String MD5Encryption ( String password ) { try { MessageDigest algorithm = MessageDigest.getInstance("MD5"); algorithm.update(password.getBytes() , 0 , password.length() ); encryptedPassword = new BigInteger( 1 , algorithm.digest()).toString(16); } catch ( NoSuchAlgorithmException ex ) { ex.printStackTrace();} return encryptedPassword; }

public void openDatabase () { DB.Open(); try { conn = DB.getConnection(); } catch ( SQLException e ) { e.printStackTrace(); } }

//this method only check username and password exclude fingerprint template public boolean login ( String userName , String password ) throws SQLException, IOException { openDatabase(); pStmt = conn.prepareStatement(logQuery); pStmt.setString( 1 , userName );

ResultSet rs = DB.retrieveData ( pStmt ); if ( rs.next()) { String encryptedPass = MD5Encryption ( password ); if ( encryptedPass.equals(rs.getString((personStatus == 0) ? "aPass" : "uPass"))) return true; else return false; } DB.close(); return false; }

//this method to register user name, password and fingerprint template public void register ( Vector<Object> objInput ) { try { openDatabase(); pStmt = conn.prepareStatement(regQuery); pStmt.setString(1 , (String) objInput.elementAt(0)); pStmt.setString(2 , (String) objInput.elementAt(1));

Page 34: Fingerprint Documentation

pStmt.setString(3 , (String) objInput.elementAt(2)); pStmt.setString(4 , (String) objInput.elementAt(3)); pStmt.setString(5 , new String((char[])objInput.elementAt(4)));

// store fingerprint template to database template = (FingerprintTemplate) objInput.elementAt(5); pStmt.setBinaryStream(6 , new ByteArrayInputStream ( template.getData()), template.getSize()); DB.insertData(pStmt);

JOptionPane.showMessageDialog(null , ((personStatus==0) ? "Administrator " : "User ") + "Registration Succesfully\n\n" + "Details :\n" + "First Name : " + (String) objInput.elementAt(0) + "\n\n" + "Last Name : " + (String) objInput.elementAt(1) + "\n\n" + "Gender : " + (String) objInput.elementAt(2) + "\n\n" + "User name : " + (String) objInput.elementAt(3) + "\n\n" + "Fingerprint Validated");

DB.close(); } catch ( SQLException e ) { e.printStackTrace(); } }

public void delete ( int userID ) { try { openDatabase(); pStmt = conn.prepareStatement(delQuery); pStmt.setInt ( 1 , userID); DB.insertData(pStmt); JOptionPane.showMessageDialog(null, "User with ID = " + userID + " has been removed from database!"); DB.close(); } catch ( SQLException ex ) { ex.printStackTrace();} }

public String getUserName (int status , String userName ) { String name = ""; try { openDatabase(); pStmt = conn.prepareStatement(nameQuery); pStmt.setString (1 , userName); ResultSet rs = DB.retrieveData(pStmt); if ( rs.next()) { if ( status == 0 ) { name = rs.getString ( "afName") + " " + rs.getString("alName"); } else name = rs.getString ( "ufName") + " " + rs.getString("ulName");

Page 35: Fingerprint Documentation

} } catch ( SQLException e ) { e.printStackTrace(); } return name; }

//method to return data based on status (User or Admin) public Object[] getUserData ( int status , String userName ) { objOutput = new Object[4]; try { openDatabase(); pStmt = conn.prepareStatement(showQuery); pStmt.setString( 1 , userName );

ResultSet rs = DB.retrieveData ( pStmt ); if ( rs.next()) { if ( status == 0 ) { objOutput[0] = rs.getInt("adminID"); objOutput[1] = rs.getString ("afName"); objOutput[2] = rs.getString ("alName"); objOutput[3] = rs.getString ("aGender"); } else { objOutput[0] = rs.getInt("userID"); objOutput[1] = rs.getString ("ufName"); objOutput[2] = rs.getString ("ulName"); objOutput[3] = rs.getString ("UGender"); } } DB.close(); } catch ( SQLException e ) { e.printStackTrace(); } return objOutput; }}

Fingerprint.java classpackage System;/** * * @author Mr. Hendry */import Storage.Database;import com.griaule.grFinger.Context;import com.griaule.grFinger.FingerCallBack;import com.griaule.grFinger.FingerprintImage;import com.griaule.grFinger.FingerprintTemplate;import com.griaule.grFinger.GrErrorException;import com.griaule.grFinger.GrFinger;import com.griaule.grFinger.ImageCallBack;

Page 36: Fingerprint Documentation

import com.griaule.grFinger.MatchingResult;import com.griaule.grFinger.StatusCallBack;import java.sql.*;

import java.io.IOException;import java.io.InputStream;import java.sql.ResultSet;import java.sql.SQLException;import javax.swing.JOptionPane;

public class Fingerprint implements StatusCallBack , ImageCallBack , FingerCallBack{ private Interface.Register register; private Interface.Login login; private GrFinger grFinger; private FingerprintImage fingerImage; //real fingerprint private FingerprintTemplate template; //template that is extracted from real fingerprint private Database DB;

public void onPlug(String idSensor) { try { // Start capturing from plugged sensor. grFinger.startCapture(idSensor,this,this); } catch (GrErrorException e) { JOptionPane.showMessageDialog(null, e.getMessage()); } }

public void onUnplug(String idSensor) { JOptionPane.showMessageDialog ( null , "Sensor: "+idSensor+". Event: Unplugged."); try { grFinger.stopCapture(idSensor); } catch (GrErrorException e) { JOptionPane.showMessageDialog ( null ,e.getMessage()); } }

public void onImage(String string, FingerprintImage fi) { try { fingerImage = fi;

//check if the caller is from register then we set the image to register fingerPanel , vice versa. if ( register != null) register.showImage(fi.newImageProducer()); else login.showImage(fi.newImageProducer()); extract();

Page 37: Fingerprint Documentation

} catch (GrErrorException e) { System.out.println("Error Detected"); } }

public void onFingerDown(String idSensor) { JOptionPane.showMessageDialog(null,"Sensor: "+idSensor+". Event: Finger Placed."); }

public void onFingerUp(String idSensor) { JOptionPane.showMessageDialog(null,"Sensor: "+idSensor+". Event: Finger Removed."); }

public void start() { // initializing fingerprint SDK... try { grFinger = new GrFinger(); grFinger.initializeCapture(this); } catch ( GrErrorException ex ) { ex.printStackTrace(); } }

public void extract () { try { //extract real fignerprint image to become template template = grFinger.extract(fingerImage, Context.DEFAULT_CONTEXT); String msg = "template extracted successfully\n";

switch (template.getImageQuality()){ case FingerprintTemplate.GR_HIGH_QUALITY: msg +="High quality."; break; case FingerprintTemplate.GR_MEDIUM_QUALITY: msg +="Medium quality."; break; case FingerprintTemplate.GR_BAD_QUALITY: msg +="Bad quality."; break; } System.out.println(msg);

if ( register != null) register.showImage(grFinger.getBiometricDisplay(template,fingerImage,Context.GR_NO_CONTEXT)); else login.showImage(grFinger.getBiometricDisplay(template,fingerImage,Context.GR_NO_CONTEXT));

Page 38: Fingerprint Documentation

} catch ( GrErrorException e ){ e.printStackTrace();} }

public void loadImage(String fileName,int resolution) { try { //Load a fingerprint image from a file grFinger.loadImageFromFile(fileName,resolution); } catch (GrErrorException e) { JOptionPane.showMessageDialog ( null,e.getMessage()); }

}

public boolean verify (String userName, FingerprintTemplate template, int status) { String query = ""; boolean valid = true; try { DB = new Database(); DB.Open(); if ( status == 0 ) query = "select aTemplate from admin where auName ='" + userName + "'"; else query = "select uTemplate from user where uuName ='" + userName + "'";

Statement stmt = DB.getConnection().createStatement(); ResultSet rs = stmt.executeQuery(query);

if ( rs.next()) { byte buffer[] = new byte [GrFinger.GR_MAX_SIZE_TEMPLATE]; InputStream stream = rs.getBinaryStream ((status == 0) ? "aTemplate" : "uTemplate"); int size = stream.read(buffer); //create new template FingerprintTemplate referenceTemplate = new FingerprintTemplate (buffer,size);

//comparing template MatchingResult result = grFinger.verify ( template , referenceTemplate , Context.DEFAULT_CONTEXT);

if ( result.doesMatched() ) valid = true; else valid = false;

login.setScore(result.getScore()); } else { System.out.println("The supplied ID does not exists"); valid = false;

Page 39: Fingerprint Documentation

} } catch ( SQLException e ) {e.printStackTrace();} catch ( IOException e2 ) {e2.printStackTrace();} catch ( GrErrorException e3) { e3.printStackTrace();} return valid; }

//set the login ( the caller from login class ) public void setLogin(Interface.Login login) { this.login = login; this.register = null; }

//set the register ( the caller from register class ) public void setRegister ( Interface.Register register ) { this.register = register; }

public FingerprintTemplate getTemplate () { return template; }

public FingerprintImage getFingerprintImage () { return fingerImage; }

public GrFinger getGrFinger() { return grFinger; }}

Validator.java classpackage System;/** * * @author Mr. Hendry */import Storage.Database;import java.sql.*;import java.util.Vector;import javax.swing.JOptionPane;

public class Validator{ public static boolean validateInput ( Vector<Object> objIn) { if ( objIn.elementAt(0).equals("") || objIn.elementAt(1).equals("") || objIn.elementAt(2).equals("") || objIn.elementAt(3).equals("") || objIn.elementAt(4).equals("") || objIn.elementAt(5).toString().equals("0")) {

Page 40: Fingerprint Documentation

if ( objIn.elementAt(0).equals("")) JOptionPane.showMessageDialog (null , "Please Fill the First Name" , "Unfilled space" ,JOptionPane.WARNING_MESSAGE); else if ( objIn.elementAt(1).equals("")) JOptionPane.showMessageDialog (null , "Please Fill the Last Name" , "Unfilled space" ,JOptionPane.WARNING_MESSAGE); else if ( objIn.elementAt(2).equals("")) JOptionPane.showMessageDialog (null , "Please Fill the User Name" , "Unfilled space" ,JOptionPane.WARNING_MESSAGE); else if ( objIn.elementAt(3).equals("")) JOptionPane.showMessageDialog (null , "Please Fill the Password" , "Unfilled space" ,JOptionPane.WARNING_MESSAGE); else if ( objIn.elementAt(4).equals("")) JOptionPane.showMessageDialog (null , "Please Fill the Password Verification" , "Unfilled space" ,JOptionPane.WARNING_MESSAGE); else if ( objIn.elementAt(5).toString().equals("0")) JOptionPane.showMessageDialog (null , "Please Enter at least 4 password characters" , "Password too short" ,JOptionPane.WARNING_MESSAGE); return false; } else return true; }

//-------- Method to check UserName and Password ------------ public static Boolean validateLogin ( String user , char[] pass) { String password = new String (pass);

if ( user.isEmpty() || password.isEmpty() ) { if (user.isEmpty() && password.isEmpty()) JOptionPane.showMessageDialog(null,"Please Enter your UserName and Password", "Login Error", JOptionPane.ERROR_MESSAGE); else if ( user.isEmpty()) JOptionPane.showMessageDialog(null,"Please Enter your UserName" , "Login Error" , JOptionPane.ERROR_MESSAGE); else JOptionPane.showMessageDialog(null,"Please Enter your Password" , "Login Error" , JOptionPane.ERROR_MESSAGE);

return false; } return true; }

//--------- Method to check for Digit in specific String ---------- public static boolean isContainDigit ( StringBuffer pass) { boolean digit = false; for ( int i = 0 ; i < pass.length() ; i++) { if ( Character.isDigit(pass.charAt(i))) { digit = true; break; }

Page 41: Fingerprint Documentation

else digit = false; } return digit; }

//------------ Check New User Name against Stored user name in database ----------- public static boolean isAvailable ( String userName , int status ) { Database DB = new Database(); DB.Open(); boolean available = true; String query;

try { Connection conn = DB.getConnection(); Statement stmt = conn.createStatement();

if ( status == 0 ) query = "select auName from admin"; else query = "select uuName from user";

ResultSet result; result = stmt.executeQuery(query);

//check current username against stored username while ( result.next() ) { if ( userName.equals(result.getString( ((status == 0) ? "auName" : "uuName")))) { available = false; } } DB.close(); } catch ( SQLException e ) { e.printStackTrace();} return available; }}

Database.java classpackage Storage;/** * * @author Mr. Hendry */

import java.sql.*;public class Database{ private ResultSet result ; private Connection conn; private Statement stmt;

Page 42: Fingerprint Documentation

//---- load jdbc driver -------- public void Open() { try { Class.forName("com.mysql.jdbc.Driver"); System.out.println("Driver loaded"); } catch ( ClassNotFoundException ex ) { ex.printStackTrace(); } }

//-------- get established connection --------- public Connection getConnection () throws SQLException { conn = DriverManager.getConnection ( "jdbc:mysql://localhost/biometricsample"); return conn; }

public void close() { try { if (result != null) { result.close(); } if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (SQLException e) { e.printStackTrace(); } }

public void insertData ( PreparedStatement pStmt ) throws SQLException { //for non-select query pStmt.executeUpdate(); }

public ResultSet retrieveData ( PreparedStatement pStmt ) throws SQLException { //for select query result = pStmt.executeQuery(); return result; }}