-1

I can match fingerprints by using sql query "where id". But i want is to identify all fingerprints on the database.

I use zk4500 fingerprint scanner. Mysql c#. sorry for my english and explanation im just a newbie..

if (bIdentify)
{

    if (userid.Text == string.Empty)
    {
        return;
    }
    // int ret = zkfp.ZKFP_ERR_OK;

    int fid = 0, score = 0;
    mysqlConn.Open();
    MySqlCommand cmd1 = mysqlConn.CreateCommand();
    cmd1.CommandText = (@"select * from emp_fingerprint where emp_id=?emp_id");
    //cmd1.Parameters.AddWithValue("?fingerprint_1", dbfp);
    cmd1.Parameters.AddWithValue("?emp_id", userid.Text);
    MySqlDataAdapter da = new MySqlDataAdapter(cmd1);
    DataTable dt = new DataTable();
    da.Fill(dt);
    dr = cmd1.ExecuteReader();
    while (dr.Read())
    {

        byte[] dbfp = new byte[2048];

        dbfp = (byte[])(dr["fingerprint_1"]);
        string a = dr["emp_id"].ToString();
        dr.Close();
        mysqlConn.Close();

        int match = zkfp2.DBMatch(mDBHandle, CapTmp, dbfp);

        if (match > 0)
        {

            textBox1.Text = "Identify success, percent= " + match + "%";

            break;
        }
        else
        {
            textBox1.Text = "Identify fail, percent= " + match + "%";
            return;
        }
    }
}

My main problem is i dont know how to store the bytes returned from the finger print scanner in the database and then query those bytes to get the user they belong too

TheGeneral
  • 79,002
  • 9
  • 103
  • 141
Sean Libiran
  • 11
  • 1
  • 1
  • 1
    Firstly format your code. This is the 3rd time you (or someone( has asked this question i have seen and it gets little response for a very good reason... There is no information to go by, it is a device few people have used and it requires searching a 3rd party site for the information. You really need to better articulate your problem. What is the data you are getting? What format is it in? How are you storing it? – TheGeneral Feb 11 '18 at 03:13
  • If you CAN supply this information in a timely fashion, ill happily remove my close flag – TheGeneral Feb 11 '18 at 03:15
  • i save it on byte format but only i can match fingerprint by using their id on database but i want to identify the id by using fingerprint – Sean Libiran Feb 11 '18 at 03:23
  • How many bytes are we talking about ? – TheGeneral Feb 11 '18 at 03:24
  • 2048 bytes per fingerprint.sir i want to know how to identify them not using where "id" clause. I try where fingerprint to but no rows return – Sean Libiran Feb 11 '18 at 04:02
  • If someone scans their finger print twice , is it likely to produce the same bytes? i'm guessing it should – TheGeneral Feb 11 '18 at 04:04
  • i think sir they produce same bytes if the fingerprint is well placed. Sir can u help me out on this cause only one fingerprint i matched everytime. i want to display "Id" depends on what fingerprint identify on system and the database. – Sean Libiran Feb 11 '18 at 04:26
  • What database are you using? – TheGeneral Feb 11 '18 at 04:56
  • Mysql and the pl is c#.net – Sean Libiran Feb 11 '18 at 05:00
  • I have updated the question and added some more detail so at least people can understand what you are trying to achieve. i have also added an answer which gives you the basic idea you need to follow. hoepfully this will help other people understand your problem, and give you a better code answer – TheGeneral Feb 11 '18 at 05:18

1 Answers1

1

Firstly

I think your database structure should probably contain a FingerPrint table with a foreign key to your users table. This would allow you to store multiple finger prints and alignments for one users.

Secondly

I don't think you can query a table via binary data, unless its stored as string.

so (and I am not sure how secure this is), you could probably hash your finger print and store the hash in the database with the finger print bytes in the FingerPrint Table as well as the User PrimaryKey

using(SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider())
{
    hash = Convert.ToBase64String(sha1.ComputeHash(byteArray));
}

When you want to look up a finger Print you can easily hash the the Finger print data, query your FingerPrint Table for the hash and return the results. You could also double check the finger print bytes you have with the results that are returned (in memory) just to be sure.

The result of all this will give you the Primary key to the User table.

Once you have the users primary key, you can then query your user for the UserId (primary key)

Update

Assuming you have a FingerPrint Table

Id     // Primary Key
UserId // Foreign key
Hash
FingerPrintData

Method To get the hash

public string GetHashFromFingerPrintData(byte[] fingerPrintData)
{
    using (SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider())
    {
        return Convert.ToBase64String(sha1.ComputeHash(fingerPrintData));
    }
}

Method to compare Finger Print bytes

public bool DoFingerPrintsMatch(byte[] a1, byte[] b1)
{
    var i = 0;
    if (a1.Length != b1.Length)
    {
        return i == a1.Length;
    }

    while ((i < a1.Length) && (a1[i] == b1[i]))
    {
        i++;
    }

    return i == a1.Length;
}

Method to Get the user Id

public int GetUserId(byte[] fingerPrintData)
{
    var connStr = "...";
    var conn = new MySqlConnection(connStr);
    var userId = -1;
    try
    {
        conn.Open();

        var sql = "SELECT UserId, FingerPrintData FROM FingerPrint WHERE Continent = @FingerPrintHash";
        var command = new MySqlCommand(sql, conn);
        command.Parameters.AddWithValue("@FingerPrintHash", fingerPrintData);
        var reader = command.ExecuteReader();

        while (reader.Read())
        {
            byte[] data = reader["FingerPrintData"];
            userId  = reader["UserId"];

            if (DoFingerPrintsMatch(fingerPrintData, data))
            {
                break;
            }

        }

        reader.Close();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
    }
    finally
    {
        conn.Close();
    }


    return userId;
}

Disclaimer : this is fully untested, but surely this should be able to point you in the right direction without having to write the program for you

TheGeneral
  • 79,002
  • 9
  • 103
  • 141