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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hashing

Status
Not open for further replies.

Dimitrie1

Programmer
Jan 5, 2007
138
CA
I have a table full of registrations and more are inserted daily. I need to hash the current passwords and the new coming in.

I'd like to use the SQL hashbytes function to hash the current records but don't know how to hash the new records thru vb.net

I've seen a few methods in vb.net but none that return the same result.

SQL
Code:
set @password= hashbytes ('SHA1',@password)

vb.net
Code:
unction getSHA1Hash(ByVal strToHash As String) As String
        Dim sha1Obj As New Security.Cryptography.SHA1CryptoServiceProvider
        Dim bytesToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(strToHash)

        bytesToHash = sha1Obj.ComputeHash(bytesToHash)


        Dim strResult As String = ""

        For Each b As Byte In bytesToHash
            strResult += b.ToString("x2")
        Next

        Return strResult
    End Function

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = TextBox1.Text
        Label2.Text = getSHA1Hash(TextBox1.ToString)
    End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top