Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving base64string to access text field

Status
Not open for further replies.

ghost807

IS-IT--Management
Jun 27, 2003
99
US
i am trying to save a text string that has been hashed using sha1 service provider.
when i try to store the hash to the database i get a sql error stating
"Syntax Error In UPDATE Statement"
yet i am using the exact same lines of code to do updates else where in the program.
my only clue is the base64string conversion.
here is the hash code.
Code:
        Dim SHA1 As SHA1CryptoServiceProvider
        Dim bytValue() As Byte
        Dim bytHash() As Byte

        ' Create New Crypto Service Provider Object
        SHA1 = New SHA1CryptoServiceProvider

        ' Convert the original string to array of Bytes
        bytValue = _
         System.Text.Encoding.UTF8.GetBytes(txtNewPass2.Text)

        ' Compute the Hash, returns an array of Bytes
        bytHash = SHA1.ComputeHash(bytValue)

        SHA1.Clear()

        ' Return a base 64 encoded string of the Hash value
        z = Convert.ToBase64String(bytHash)
and here is the udpate command, it's not pretty yet but it will be when i'm done.

Code:
        Dim connect As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPath
        Dim conn As New OleDbConnection(connect)
        Dim adapter As New OleDbDataAdapter
        Dim sqlString As String = "SELECT * FROM tblEmployees"
        adapter.SelectCommand = New OleDbCommand(sqlString, conn)
        Dim cmdBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(adapter)
        Dim BarCodeUpdate As New Database

        Try
            conn.Open()

            ' update the record
            adapter.TableMappings.Add("Table", "tblEmployees")
            adapter.Fill(BarCodeUpdate.Tables("tblEmployees"))

            Dim idx As Integer
            'Dim nullVal As DBNull
            For idx = 0 To BarCodeUpdate.tblEmployees.Rows.Count - 1
                'If BarCodeUpdate.tblMovie(idx).BarCode.ToUpper = BarCode Then
                If BarCodeUpdate.tblEmployees(idx).Employee = txtUserName.Text.ToUpper Then
                    BarCodeUpdate.tblEmployees(idx).Password = z
                End If
                'End If
            Next

            adapter.Update(BarCodeUpdate)
            BarCodeUpdate.Dispose()
            adapter.Dispose()
            conn.Dispose()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top