vb.net 如何使用VB在phpmyadmin数据库中保存和检索指纹模板

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13578909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:19:32  来源:igfitidea点击:

How to save and retrieve a fingerprint template in phpmyadmin database, using VB

vb.netphpmyadminfingerprintbiometrics

提问by godslove

We are using digital persona for our biometrics. We can already save employee ID, employee name and assigned finger .Our problem is that we dont know how to save a fingerprint template to a database and retrieve it so that it can still be read and verified by the biometric scanner. The file extension is ".ftp" .

我们正在使用数字角色进行生物识别。我们已经可以保存员工 ID、员工姓名和分配的手指。我们的问题是我们不知道如何将指纹模板保存到数据库中并检索它,以便它仍然可以被生物识别扫描仪读取和验证。文件扩展名是“.ftp”。

CODE:

代码:

Private Sub buttonRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonRegister.Click

        'Does user already exists
        Dim bUserExists As Boolean = _Users.UserExists(New UserID(textBoxUserName.Text))

        ' first make sure the user is created if new user
        If _ActiveUser Is Nothing Or Not bUserExists Then
            ' initialize with supplied user name
            _ActiveUser = New User(textBoxUserName.Text)
        Else
            ' update active user if not as originally selected
            If bUserExists And Not listBoxUsers.SelectedItem.ToString() = textBoxUserName.Text Then
                _ActiveUser = _Users(New UserID(textBoxUserName.Text))
            End If
        End If

        ' and check if the template already exists for the assigned finger
        If _ActiveUser.TemplateExists(_AssignedFinger) Then
            ' show message indicating template already exists for selected finger
            Dim diagResult As DialogResult = MessageBox.Show(Me, [String].Format("Oops!" + ControlChars.Cr + ControlChars.Lf + "{0} has a template enrolled to his/her {1} finger." + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf + "Shall the old template be discarded?", _ActiveUser.ID.ToString(), _Fingers(_AssignedFinger)), "Template already assigned!", MessageBoxButtons.YesNo, MessageBoxIcon.Error)

            ' if user selected not to overwrite, then abort
            If diagResult = Windows.Forms.DialogResult.No Then
                Return
            End If
        End If

        Try
            ' attempt to read the template
            Dim templateOpened As New DPFP.Template(File.OpenRead(textBoxTemplateFilename.Text))

            ' run a template duplicate check
            IdentifyTemplate(templateOpened)

            ' remove the old template if exists
            If _ActiveUser.TemplateExists(_AssignedFinger) Then
                ' removed from assigned finger
                _ActiveUser.RemoveTemplate(_AssignedFinger)
            End If

            ' and assign it to the user as specified
            _ActiveUser.AddTemplate(templateOpened, _AssignedFinger)

            ' update collection
            If Not _Users.UserExists(_ActiveUser.ID) Then
                ' update list box
                listBoxUsers.Items.Add(_ActiveUser.ID.ToString())

                ' add user it to the user collection
                _Users.AddUser(_ActiveUser)
            End If

            ' success
            UpdateEventLog([String].Format("{0}: Template successfully assigned to {1} finger.", _ActiveUser.ID.ToString(), _AssignedFinger.ToString()))

            ' turn off groupbox
            groupAddTemplate.Visible = False

            listBoxUsers.SelectedItem = _ActiveUser.ID.ToString()

            ' sync gui
            _syncUI()

            ' view user
            _syncViewUser()

        Catch Err As DPFP.Error.SDKException
            ' log message
            UpdateEventLog(Err.ToString())
            System.Diagnostics.Trace.WriteLine(Err.ToString())
        Catch Err As System.IO.FileNotFoundException
            ' log message
            UpdateEventLog("Template file not found or is inaccessible.")
            System.Diagnostics.Trace.WriteLine(Err.ToString())
        Catch Err As Exception
            ' log message
            UpdateEventLog(Err.ToString())
            System.Diagnostics.Trace.WriteLine(Err.ToString())
        End Try

        Using conn As New MySqlConnection("Server = localhost; Username= root; Password =; Database = vb")
            Using cmd
                With cmd
                    MsgBox("Connection Established")
                    .Connection = conn
                    .Parameters.Clear()
                    'Create Insert Query
                    .CommandText = "INSERT INTO employees(UserID, Name, Finger) VALUES (@iID, @iName, @iFinger)"
                    .Parameters.Add(New MySqlParameter("@iID", ID.Text))
                    .Parameters.Add(New MySqlParameter("@iName", textBoxUserName.Text))
                    .Parameters.Add(New MySqlParameter("@iFinger", comboBoxAssignedFinger.Text))


                End With
                Try
                    'Open Connection and Execute Query
                    conn.Open()
                    cmd.ExecuteNonQuery()
                Catch ex As MySqlException
                    MsgBox(ex.Message.ToString())
                End Try
            End Using
        End Using

回答by dynamicnetpaper

i know that this is an old post but here are code blocks that might help...

我知道这是一篇旧帖子,但这里的代码块可能会有所帮助...

IN SAVING I USED THIS

在保存时我使用了这个

       For Each template As DPFP.Template In Data.Templates    
            If Not template Is Nothing Then 
                cmd = New MySqlCommand("INSERT INTO employeefp " +
                                  "SET No=@No, " +
                                  "FP=@FP " +
                                  " ", conn)

                cmd.Parameters.Add(New MySqlParameter("@No", txtEmpNo.Text))
                cmd.Parameters.Add(New MySqlParameter("@FP", template.Bytes))

                cmd.ExecuteNonQuery()

            End If
        Next

IN VERIFYING FROM THE DB I USED THIS

在从数据库验证时,我使用了这个

  1. WHEN FORM IS LOADED I FETCH ALL THE FINGER PRINTS

        Dim cmd As New MySqlCommand("SELECT * FROM employeefp  ", conn)
        Dim rdr As MySqlDataReader = cmd.ExecuteReader()
    
        While (rdr.Read())
            Dim MemStream As IO.MemoryStream
            Dim fpBytes As Byte()
    
            fpBytes = rdr("FP")
            MemStream = New IO.MemoryStream(fpBytes)
    
            Dim templa8 As DPFP.Template = New DPFP.Template()
            templa8.DeSerialize(MemStream)
    
            Dim tmpObj As New AppData
            tmpObj.No = rdr("No").ToString()
            tmpObj.Template = templa8
            FPList.Add(tmpObj)
        End While
    
  1. 加载表格时,我会获取所有指纹

        Dim cmd As New MySqlCommand("SELECT * FROM employeefp  ", conn)
        Dim rdr As MySqlDataReader = cmd.ExecuteReader()
    
        While (rdr.Read())
            Dim MemStream As IO.MemoryStream
            Dim fpBytes As Byte()
    
            fpBytes = rdr("FP")
            MemStream = New IO.MemoryStream(fpBytes)
    
            Dim templa8 As DPFP.Template = New DPFP.Template()
            templa8.DeSerialize(MemStream)
    
            Dim tmpObj As New AppData
            tmpObj.No = rdr("No").ToString()
            tmpObj.Template = templa8
            FPList.Add(tmpObj)
        End While
    

NOTE : Dim FPList As List(Of AppData) = New List(Of AppData) //you can find the definition of this in the SDK i just added Template (contains one print) aside from the existing Templates(contains many print)

注意:Dim FPList As List(Of AppData) = New List(Of AppData) //你可以在SDK中找到这个定义我刚刚添加了模板(包含一个打印)除了现有的模板(包含许多打印)

  1. COMPARE THE CURRENT SAMPLE FROM THE MACHINE

    Sub OnComplete(ByVal Control As Object, ByVal FeatureSet As DPFP.FeatureSet, ByRef EventHandlerStatus As DPFP.Gui.EventHandlerStatus) Handles VerificationControl.OnComplete
    Dim printFound As Boolean = False
    VerifiedFPData = New AppData
    Try
        For Each FPData As AppData In FPList
            Dim tmplateData As New DPFP.Template
            tmplateData = FPData.Template
            Dim compareTo As New DPFP.FeatureSet
            compareTo = FeatureSet
    
            Dim ver As New DPFP.Verification.Verification()
            Dim res As New DPFP.Verification.Verification.Result()
    
            If Not tmplateData Is Nothing Then
                ver.Verify(FeatureSet, tmplateData, res)
    
                If res.Verified Then
                    EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Success
                    printFound = True
                    VerifiedFPData = FPData
                    Exit For ' success
                End If
            End If
        Next
    Catch ex As Exception
        MessageBox.Show("verification error")
    End Try
    
    
    If printFound Then
        //TO DO 
    Else
        EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Failure
        // TODO
    End If
    

    End Sub

  1. 比较机器的当前样品

    Sub OnComplete(ByVal Control As Object, ByVal FeatureSet As DPFP.FeatureSet, ByRef EventHandlerStatus As DPFP.Gui.EventHandlerStatus) Handles VerificationControl.OnComplete
    Dim printFound As Boolean = False
    VerifiedFPData = New AppData
    Try
        For Each FPData As AppData In FPList
            Dim tmplateData As New DPFP.Template
            tmplateData = FPData.Template
            Dim compareTo As New DPFP.FeatureSet
            compareTo = FeatureSet
    
            Dim ver As New DPFP.Verification.Verification()
            Dim res As New DPFP.Verification.Verification.Result()
    
            If Not tmplateData Is Nothing Then
                ver.Verify(FeatureSet, tmplateData, res)
    
                If res.Verified Then
                    EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Success
                    printFound = True
                    VerifiedFPData = FPData
                    Exit For ' success
                End If
            End If
        Next
    Catch ex As Exception
        MessageBox.Show("verification error")
    End Try
    
    
    If printFound Then
        //TO DO 
    Else
        EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Failure
        // TODO
    End If
    

    结束子

hope it helps someone :)

希望它可以帮助某人:)

回答by user3505171

There are some missing codes from the answer above. The code of the class appdata is missing.These code is error without declaring first the tmpObj in the class AppData. Dim tmpObj As New AppData tmpObj.No = rdr("No").ToString() tmpObj.Template = templa8 FPList.Add(tmpObj)

上面的答案中缺少一些代码。缺少类appdata 的代码。这些代码是错误的,没有先在类AppData 中声明tmpObj。Dim tmpObj As New AppData tmpObj.No = rdr("No").ToString() tmpObj.Template = templa8 FPList.Add(tmpObj)