I am using VB .NET and I was trying to use a hash function which i found in a VB .NET help file but it gave me a input parameter error, stating that it is incorrect format.
For the password field and variable, I am using byte() in VB .NET and varbinary in the SQL server database. what type should i use in the database for it to accept it?
Hash function code I used:
Code:
Public Function CreateDBPassword(ByVal password As String) As Byte()
' Create the unsalted password hash.
Dim UnsaltedPassword() As Byte = CreatePasswordHash(password)
' Generate a random salt value.
Dim SaltValue(SaltLength - 1) As Byte
Dim Rng As New RNGCryptoServiceProvider
Rng.GetBytes(SaltValue)
' Create the salted hash.
Return CreateSaltedPassword(SaltValue, UnsaltedPassword)
End Function
' This function returns a password hash
' that hasn't been salted.
Private Function CreatePasswordHash(ByVal password As String) As Byte()
Dim Sha1 As New SHA1Managed
Return Sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password))
End Function
' This function accepts the password hash, and
' salts it with the given salt value.
Private Function CreateSaltedPassword(ByVal saltValue As Byte(), _
ByVal unsaltedPassword() As Byte) As Byte()
' Add the salt to the hash.
Dim RawSalted(unsaltedPassword.Length + saltValue.Length - 1) As Byte
unsaltedPassword.CopyTo(RawSalted, 0)
saltValue.CopyTo(RawSalted, unsaltedPassword.Length)
' Create the salted hash.
Dim Sha1 As New SHA1Managed
Dim SaltedPassword() As Byte = Sha1.ComputeHash(RawSalted)
' Add the salt value to the salted hash.
Dim DbPassword(SaltedPassword.Length + saltValue.Length - 1) As Byte
SaltedPassword.CopyTo(DbPassword, 0)
saltValue.CopyTo(DbPassword, SaltedPassword.Length)
Return DbPassword
End Function