Click here to Skip to main content
16,007,885 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using visual studio and trying to verify a fingerprint template and to generate the record that corresponds to the fingerprint i scanned using uareu fingerprint reader. The entire verification code is below. Please help me find this error as i am just getting excited with c# programming

using DPFP;
using DPFP.Capture;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Mysqlx.Notice.Warning.Types;
using System.IO;


namespace ExaminationAuthentication
{
    public partial class verificationForm : Form, DPFP.Capture.EventHandler
    {

        private DPFP.Capture.Capture Capturer;
        private DPFP.Verification.Verification Verificator;

        public verificationForm()
        {
            InitializeComponent();
            Verificator = new DPFP.Verification.Verification();
        }

        public void OnComplete(object Capture, string ReaderSerialNumber, DPFP.Sample Sample)
        {
            this.Invoke(new Action(() =>
            {
                MakeReport("The fingerprint sample was captured. Checking against the database...");
                try
                {
                    Process(Sample);
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Error during processing: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }));
        }

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

        public void OnFingerTouch(object Capture, string ReaderSerialNumber)
        {
            SetStatus("The fingerprint reader was touched.");
        }

        public void OnReaderConnect(object Capture, string ReaderSerialNumber)
        {
            SetStatus("The fingerprint reader was connected.");
        }

        public void OnReaderDisconnect(object Capture, string ReaderSerialNumber)
        {
            SetStatus("The fingerprint reader was disconnected.");
        }

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


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

        protected void MakeReport(string message)
        {
            this.Invoke(new Action(delegate ()
            {
                StatusText.AppendText(message + "\r\n");
            }));
        }
      

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


        protected virtual void Process(DPFP.Sample Sample)
        {
            this.Invoke(new Action(() =>
            {
                Bitmap fingerprint = ConvertSampleToBitmap(Sample);
                DrawPicture(fingerprint);

                // Extract features from the fingerprint sample
                DPFP.FeatureSet features = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification);

                if (features != null)
                {
                    VerifyFingerprint(features);
                }
                else
                {
                    MessageBox.Show("The fingerprint quality is poor. Please try again.", "Quality Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }));
        }


        private DPFP.FeatureSet ExtractFeatures(DPFP.Sample Sample, DPFP.Processing.DataPurpose Purpose)
        {
            DPFP.Processing.FeatureExtraction extractor = new DPFP.Processing.FeatureExtraction();
            DPFP.Capture.CaptureFeedback feedback = DPFP.Capture.CaptureFeedback.None;
            DPFP.FeatureSet features = new DPFP.FeatureSet();

            try
            {
                extractor.CreateFeatureSet(Sample, Purpose, ref feedback, ref features);
                if (feedback == DPFP.Capture.CaptureFeedback.Good)
                {
                    return features;
                }
                else
                {
                    MakeReport("The fingerprint sample quality is not sufficient.");
                    return null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error extracting features: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }
        }


        private void VerifyFingerprint(DPFP.FeatureSet features)
        {
            string connectionString = "server=localhost;user=root;database=ivs;password=";

            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                string query = "SELECT * FROM students";

                using (MySqlCommand cmd = new MySqlCommand(query, connection))
                {
                    try
                    {
                        connection.Open();
                        using (MySqlDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                byte[] storedFingerprint = (byte[])reader["fingerprint"];
                                DPFP.Template template = new DPFP.Template();
                                template.DeSerialize(storedFingerprint);

                                DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result();
                                Verificator.Verify(features, template, ref result);

                                if (result.Verified)
                                {
                                    MessageBox.Show("Fingerprint match found! Retrieving user data...");

                                    // Display the user's details
                                    DisplayUserData(reader);
                                    return;
                                }
                            }
                        }

                        MessageBox.Show("No matching fingerprint found in the database.", "Authentication Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"An error occurred: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }


        private void DisplayUserData(MySqlDataReader reader)
        {
            // Assuming you have text boxes and other controls named accordingly on your form
            txtSurname.Text = reader["surname"].ToString();
            txtOthernames.Text = reader["othernames"].ToString();
            txtSex.Text = reader["sex"].ToString();
            txtDOB.Value = Convert.ToDateTime(reader["dob"]); // Assuming txtDOB is a DateTimePicker
            txtPhoneNumber.Text = reader["phoneNumber"].ToString();
            txtEmailAddress.Text = reader["emailAddress"].ToString();
            txtResidentialAddress.Text = reader["residentialAddress"].ToString();
            txtStateOfOrigin.Text = reader["stateOfOrigin"].ToString();
            txtLocalGovernmentArea.Text = reader["localGovernmentArea"].ToString();
            txtMatricNumber.Text = reader["matricNumber"].ToString();
            txtLevel.Text = reader["level"].ToString();
            txtDepartment.Text = reader["department"].ToString();
            txtSchool.Text = reader["school"].ToString();

            // Convert the timestamp to a DateTime format and display it
            txtTimestamp.Text = Convert.ToDateTime(reader["timestamp"]).ToString("yyyy-MM-dd HH:mm:ss");

            // Convert the byte array from the database back into an Image for the passport
            byte[] passportData = (byte[])reader["passport"];
            if (passportData != null && passportData.Length > 0)
            {
                using (MemoryStream ms = new MemoryStream(passportData))
                {
                    pbPassport.Image = Image.FromStream(ms); // Display the passport image in the PictureBox
                }
            }

            // Display a success message
            MessageBox.Show("User data retrieved successfully and populated in the form.", "Data Retrieved", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }


        protected Bitmap ConvertSampleToBitmap(DPFP.Sample Sample)
        {
            DPFP.Capture.SampleConversion Convertor = new DPFP.Capture.SampleConversion();
            Bitmap bitmap = null;
            try
            {
                Convertor.ConvertToPicture(Sample, ref bitmap);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error converting sample to bitmap: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return bitmap;
        }

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

        private byte[] SampleToByteArray(DPFP.Sample sample)
        {
            DPFP.Capture.SampleConversion converter = new DPFP.Capture.SampleConversion();
            Bitmap bitmap = null;
            converter.ConvertToPicture(sample, ref bitmap);

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                return ms.ToArray();
            }
        }

        private void verificationForm_FormClosed(object sender, FormClosedEventArgs e)
        {
           
        }

        private void btnStopCapture_Click(object sender, EventArgs e)
        {
            if (Capturer != null)
            {
                try
                {
                    Capturer.StopCapture();
                    MakeReport("Stopped scanning the fingerprint.");
                }
                catch
                {
                    MakeReport("Can't terminate Capture.");
                }
            }
        }

        private void btnCaptureFingerprint_Click(object sender, EventArgs e)
        {
            if (Capturer != null)
            {
                try
                {
                    Capturer.StartCapture();
                    MakeReport("Using the fingerprint reader, scan your fingerprint.");
                }
                catch
                {
                    MakeReport("Can't initiate Capture.");
                }
            }
        }
    }
}


Thanks you for your help

What I have tried:

I dont know much about C# programming so please help me as you can.
Once again, this is the problem I am facing:
"An error occured: Exception from HRESULT: 0xFFFFFFF8"
Posted
Comments
RedDk 2-Sep-24 17:42pm    
What are the chances?
CP reference ->https://www.codeproject.com/questions/1005849/how-to-verify-dpfp-finger-print-from-ms-sql-in-csh

1 solution

@RedDK comment moved to solution:

What are the chances?
CP reference ->how to verify DPFP finger print from MS SQL in C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900