<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.unioncomm.sdk.bsp.UCBioBSPJNI" %>
<%@ page import="java.io.*" %>

<% request.setCharacterEncoding("UTF-8"); %>
<%
  // Declaration variable
  String curPath, tmpPath;
  String msg;
  String UserID, UserPWD; //, FIRTextData
  String fUserID, fFIRSize;// , fFIRTextData
  
  File f = null;
  BufferedReader reader = null;
  UCBioBSPJNI bsp = new UCBioBSPJNI();
  UCBioBSPJNI.FIR_TEXTENCODE FIRTextData = bsp.new FIR_TEXTENCODE();
  UCBioBSPJNI.FIR_TEXTENCODE fFIRTextData = bsp.new FIR_TEXTENCODE();
  UCBioBSPJNI.INPUT_FIR InputFIR = bsp.new INPUT_FIR();
  UCBioBSPJNI.INPUT_FIR fInputFIR = bsp.new INPUT_FIR();
  
  UserID = request.getParameter("UserID");
  FIRTextData.TextFIR = request.getParameter("FIRTextData");
  
  // Get current path
//  tmpPath = getServletContext().getRealPath(request.getRequestURI());
  tmpPath = getServletContext().getRealPath("/");
  tmpPath = tmpPath.substring(0, tmpPath.lastIndexOf("\\"));
  curPath = tmpPath + "\\FDB\\";
  
  
  // Check file exist
  f = new File(curPath + UserID  + ".FDB");
  if ( !f.exists() ) {
  	// File not found error
  	msg = "User not found! (UserID: " + UserID + ")";
  } else {
  	// Read fir data form file
	reader = new BufferedReader(new FileReader(f));
  	
  	// Read user id and fir data form file
  	fUserID			= reader.readLine();
  	fFIRSize		= reader.readLine();
  	fFIRTextData.TextFIR	= reader.readLine();
  	
  	reader.close();
  	
  	// Match captured fir data with stored fir data
  	
  	// Set UCBioBSPCOM object
	InputFIR.SetTextFIR(FIRTextData);
	fInputFIR.SetTextFIR(fFIRTextData);
    
  	// Verify Match
	Boolean bResult = new Boolean(false); // never use like as 'Boolean bResult = false'.
	
  	int ret = bsp.VerifyMatch(InputFIR, fInputFIR, bResult, null);
	
	if (ret == 0) {
		if (bResult.booleanValue()) {
  	 		msg = "Verification success!";
		} else {
			msg = "Verification failed!";
		}
	} else {
  		msg = "Error! (" + bsp.GetErrorCode() + ")";
	}
	
  }

%>

<html>

<body>

<center>
<hr>
<H2>Demo Page for Verification (Result)</H2>
<hr>

<br>

<b>User ID : <%= UserID %></b>

<br>
<br>
<br>

<font size=5 color=#000080><b><%= msg %></b></font>
<hr noshade width=300>

<br>

<br>
<input type=button OnClick="javascript:location.href='./default.jsp';" value=" << Return to Home ">
<br>
<p>

<br>

<hr>
<font size=2>Copyright ⓒ 2008. UNION COMMUNITY Co., Ltd.</font>
</center>

</body>
</html>
