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

时间:2012-11-27 06:56:12

标签: vb.net phpmyadmin fingerprint biometrics

我们正在使用数字角色来进行生物识别。我们已经可以保存员工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

2 个答案:

答案 0 :(得分:2)

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

拯救我使用了这个

       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

从我使用的数据库验证

  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
    
  2. 注意:Dim FPList As List(Of AppData)= New List(Of AppData)//你可以在SDK中找到这个的定义我刚刚添加了模板(包含一个打印件),除了现有的模板(包含很多打印件) )

    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
      

      End Sub

    2. 希望它可以帮助某人:)

答案 1 :(得分:1)

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