Digital Persona Fingerprint Verification in C#

36 Views Asked by At

I am trying to create a fingerprint scanning system using C#. I am now able to save data in the database but I have no idea how to verify the fingerprint that is being saved in the database.

Here is my currently working code:

public partial class ScannerForm : Form, DPFP.Capture.EventHandler
{
    private DPFP.Capture.Capture Capturer;
    public ScannerForm()
    {
        InitializeComponent();
    }

    protected void MakeReport(string message)
    {
        this.Invoke(new Action(delegate ()
        {
            lblStatus.Text = message;
        }));
    }

    private void ScannerForm_Load(object sender, EventArgs e)
    {
        try
        {
            Capturer = new DPFP.Capture.Capture();
            if(Capturer != null)
            {
                Capturer.EventHandler = this;
                MakeReport("Press button to start operation");
                
            }
            else
            {
                MakeReport("Cannot start operation");
            }
        }
        catch
        {
            MessageBox.Show("Cannot initiate capture operation", "Error", MessageBoxButtons.OK,  MessageBoxIcon.Error);
        }
    }

    public void OnReaderConnect(object Capture, string ReaderSerialNumber)
    {
        MakeReport("The fingerprint reader is connected");
    }

    public void OnReaderDisconnect(object Capture, string ReaderSerialNumber)
    {
        MakeReport("The fingerprint reader is disconnected");
    }

    public void OnFingerGone(object Capture, string ReaderSerialNumber)
    {
        MakeReport("The finger is removed from the fingerprint reader");
    }

    public void OnFingerTouch(object Capture, string ReaderSerialNumber)
    {
        MakeReport("The finger is touching the fingerprint reader");
    }

    public void OnComplete(object Capture, string ReaderSerialNumber, DPFP.Sample Sample)
    {
        MakeReport("The fingerprint was captured");
        Process(Sample);
    }

    public void OnSampleQuality(object Capture, string ReaderSerialNumber, DPFP.Capture.CaptureFeedback CaptureFeedback)
    {
        if(CaptureFeedback == DPFP.Capture.CaptureFeedback.Good)
        {
            MakeReport("The quality of fingerprint sample is good");
        }

        else
        {
            MakeReport("The quality of fingerprint sample is poor");
        }
    }

    //Process

    protected virtual void Process(DPFP.Sample Sample)
    {
        DrawPicture(ConvertSampleToBitmap(Sample));
        
    }

    protected Bitmap ConvertSampleToBitmap(DPFP.Sample Sample)
    {
        DPFP.Capture.SampleConversion Convertor = new DPFP.Capture.SampleConversion();
        Bitmap bitmap = null;
        Convertor.ConvertToPicture(Sample, ref bitmap);

        return bitmap;
    }

    private void DrawPicture(Bitmap bitmap)
    {
        pbImage.Image = new Bitmap(bitmap, pbImage.Size);
    }

    private void btnCapture_Click(object sender, EventArgs e)
    {
        if(Capturer != null)
        {
            try
            {
                Capturer.StartCapture();
                MakeReport("Using the fingerprint scanner, scan your fingerprint");
            }
            catch
            {
                MakeReport("Cannot initiate operation");
            }
        }
    }

    private void btnInsert_Click(object sender, EventArgs e)
    {

        MySqlConnection conn = new MySqlConnection("datasource=localhost;port=3306;username=root;password='';database=db_visitorapp; SSL Mode = None");
        MySqlCommand command;
        MySqlDataAdapter DA;
        DataTable dt;

        try
        {
            conn.Open();
            string user_name = tbName.Text;
            Image fingerprintImg = pbImage.Image;
            ImageConverter Converter = new ImageConverter();
            var ImageConvert = Converter.ConvertTo(fingerprintImg, typeof(byte[]));
            string mysql_query = "INSERT INTO tbl_user (name, fingerprint) VALUES (@name, @fingerprint)";
            MySqlCommand command1 = new MySqlCommand(mysql_query, conn);
            command1.Parameters.AddWithValue("@name", tbName.Text);
            command1.Parameters.AddWithValue("@fingerprint", ImageConvert);

            command1.ExecuteNonQuery();
            MessageBox.Show("Record inserted successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        finally
        {
            conn.Close();
        }
    }
}
0

There are 0 best solutions below