Click here to Skip to main content
16,012,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Hi, I'm trying to setup a Login with fingerPrints. The idea is to select username from a combobox and provide fingerprint.  The pair is then compared against database stored values and if a match is hit Access is granted.

The datatype of the print is 'image' in the database however to store it i have to convert it to an array of type byte.
ComboBox1 DropDownStyle is DropDownList

My idea is to convert whatever is in the picture box to the same datatype and then compare.
 I have not been successful. I keep receiving the message ;
{"The data types image and varbinary(max) are incompatible in the equal to operator."}
raised at >> dr = clgq.ExecuteReader(); <<

what do i need to to get this right. I already included the System.Drawing.Imaging, System.IO, Libraries.Help Please


What I have tried:

C#
private void button2_Click(object sender, EventArgs e)
            {
            string lgq = "select name, picture from photo where name= '" + comboBox1.Text + "' and picture= @pc";
            

            MemoryStream ms = new MemoryStream();//Declare a memory stream
            pictureBox1.Image.Save(ms, ImageFormat.Jpeg);//Create a value of PictureBox1 as a memory stream with jpg encoding
            byte[] pic = ms.ToArray(); //convert this memory stream to an array of bytes

            SqlCommand clgq = new SqlCommand(lgq, con);
            clgq.Parameters.AddWithValue("@pc", pic);

            SqlDataReader dr;
            dr = clgq.ExecuteReader();
            int T = 0;
            while(dr.Read())
                {
                T++;
                }
            if (T == 1)
                MessageBox.Show("Login Successful", " ", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
                MessageBox.Show("Login Not Successful", " ", MessageBoxButtons.OK, MessageBoxIcon.Stop);

            }
Posted
Updated 19-Nov-16 2:06am

1 solution

OK...converting an image to bytes (so you can store them) and back to an image (when you retrieve them) is pretty easy - you've done one side. Converting from bytes to image you don't need to do - the SQL SELECT will return an array of bytes, which you cna just cast.
But...this approach won't work.
Firstly, what you are doing is dangerous: Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

Secondly, you can't ask SQL to compare two byte arrays - it doesn't do that, so you need to retrieve the byte data from SQL and compare it yourself, rather than expect SQL to do it for you.

Thirdly - and this is the biggie - it will almost certainly never match. Think about the resolution of whatever you are scanning the fingerprint with, and now think about these: is there a single grain of dust on the lens? If there is, the two images will not be the same. Is the finger rotated even infinitesimally compared to when it was originally scanned? If so... Is the finger moved even a tiny fraction of a millimetre vertically or horizontally compared to the original? If so...
It will always be different. To compare fingerprints, you don;t compare images, you need to look for the significant shapes, fold, whorls, breaks, and such like that make them unique. It's not as trivial as "is this picture identical to that one?"
 
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