How to create a fingerprint scanner software using C#?

capture fingerprint image and upload to database in C#

Fingerprint authentication has been widely used for time and attendance and workforce management. And it is now used more and more for identity management due to its accuracy and ease of use. To create a fingerprint scanner system, the first job would be to capture images of fingers from fingerprint scanners.

However, the problem is that there is currently not a general API to support all fingerprint devices. Different fingerprint scanners usually come with their own SDK which lack flexibility which limit the usage of your application. Also, the SDK coming with the device usually doesn’t provide API for you to upload the scanned images to your server or database directly.

Here we will show how to use Dynamic .NET TWAIN SDK to easily create a fingerprint scanning software with C#. The SDK works with all fingerprint scanners with a TWAIN driver.

Access TWAIN compatible fingerprint readers

TWAIN is a protocol for communication between software applications and imaging devices like scanners, cameras etc. Dynamic .NET TWAIN is a C# wrapper of TWAIN API. With it, you can easily capture images from TWAIN fingerprint devices and upload the images to your server, database or local disk in your C# or VB.NET application.

Here you can find a list of TWAIN compatible fingerprint scanners (not complete).

If you already acquired the fingerprint devices, you can test it with the online demo of Dynamic Web TWAIN to verify if it is TWAIN complaint.

Below we will show the code snippets to achieve fingerprint image capture and uploading to SQL server database.

Scan fingerprint images

Dynamic .NET TWAIN provides easy APIs for you to access TWAIN fingerprint scanners. You can capture image with just a few lines of code.

private void AcquireImage()
{
try {
	dynamicDotNetTwain1.SelectSourceByIndex(Convert.ToInt16(cmbSource.SelectedIndex));
	dynamicDotNetTwain1.OpenSource();
	dynamicDotNetTwain1.IfDisableSourceAfterAcquire = true;
	
	dynamicDotNetTwain1.AcquireImage();
	}
catch (Exception exp)
{
	this.txtboxErrMessage.AppendText(exp.Message);
	this.txtboxErrMessage.AppendText("\r\n");
}
}

Upload fingerprint images to Server and SQL server database

Dynamic .NET TWAIN provides HTTP POST methods which enables you to upload captured images to server or database as JPG, PNG, BMP, single-page or multi-page TIFF or PDF files. Here you can see the code of how to upload images to SQL Server.

Upload button code – send image data to server side

private void btnUpload_Click(object sender, EventArgs e)
{
try {
	dynamicDotNetTwain1.SetHTTPFormField("ExtraTxt", this.txtboxExtraTxt.Text); // pass extra text parameters when uploading image
	dynamicDotNetTwain1.HTTPUploadThroughPost("localhost", 1, "SaveToDB.aspx", "test.jpg");
}
catch (Exception exp)
{
	this.txtboxErrMessage.AppendText(exp.Message);
	this.txtboxErrMessage.AppendText("\r\n");
}
}

SaveToDB.aspx – receive and save the images to SQL Server

<%@ Page Language="C#"%>
<%
string strImageName = "";
try
{
string DW_SaveTable = "tblWebTwain4";
string DW_ConnString = "Server=localhost\\sqlexpress;Database=DemoWebTwain;User ID=sa;Password=DefeGedetf;Trusted_Connection=False";
//string DW_ConnString = "Server=localhost;Database=DemoWebTwain;Integrated Security=SSPI";

int iFileLength;
HttpFileCollection files = HttpContext.Current.Request.Files;
HttpPostedFile uploadfile = files["RemoteFile"];
if (uploadfile != null)
{
strImageName = uploadfile.FileName;
iFileLength = uploadfile.ContentLength;

Byte[] inputBuffer = new Byte[iFileLength];
System.IO.Stream inputStream;

inputStream = uploadfile.InputStream;
inputStream.Read(inputBuffer, 0, iFileLength);

String strConnString;

strConnString = DW_ConnString;

System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(strConnString);

String SqlCmdText = "INSERT INTO " + DW_SaveTable + " (strImageName,imgImageData) VALUES (@ImageName,@Image)";
System.Data.SqlClient.SqlCommand sqlCmdObj = new System.Data.SqlClient.SqlCommand(SqlCmdText, sqlConnection);

sqlCmdObj.Parameters.Add("@Image", System.Data.SqlDbType.Binary, iFileLength).Value = inputBuffer;
sqlCmdObj.Parameters.Add("@ImageName", System.Data.SqlDbType.VarChar, 255).Value = strImageName;

sqlConnection.Open();
sqlCmdObj.ExecuteNonQuery();
sqlConnection.Close();

}
}
catch (Exception exp)
{
}
%>

You can download and try the demo applications of Dynamic .NET TWAIN in the code gallery.

To embed fingerprint scanning to your .NET desktop application, you can download a 30-day free trial of Dynamic .NET TWAIN.
Download 30-day free trial

If you need fingerprint reading in your Web application, Dynamic Web TWAIN, which is a TWAIN JS library, would satisfy your needs.

Subscribe Newsletter

Subscribe to our mailing list to get the monthly update.

Subscribename@email.com