Question : Diffrent vb.net and Sql Server MD5 hashing

Hi,

sorry for being dump in this subject :)

I'm working on my graduation project and i need some help in understanding the cryptography in sql server and vb.net. i have a user table in sql server which i have trigger inside it to hash the password. and in my vb I have a login screen that is connected to my uses table.

this is my triggers:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
CREATE TRIGGER before_insert_user
   ON  users
   INSTEAD OF INSERT
AS
BEGIN
    SET NOCOUNT ON;
    if exists (Select * from inserted i inner join users t
          on t.user_login_id=i.user_login_id and t.member_id=i.member_id)
          raiserror('Duplicated user login name',16,1)
    else
          insert users
          select user_login_id, user_full_name, member_id, HASHBYTES('MD5',password_temp), ''
          from inserted
END
GO



and this is my function in vb.net

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
  Private Function GenerateHash(ByVal SourceText As String) As String
        'Create an encoding object to ensure the encoding standard for the source text
        Dim Ue As New UnicodeEncoding()
        'Retrieve a byte array based on the source text
        Dim ByteSourceText() As Byte = Ue.GetBytes(SourceText)
        'Instantiate an MD5 Provider object
        Dim Md5 As New MD5CryptoServiceProvider()
        'Compute the hash value from the source
        Dim ByteHash() As Byte = Md5.ComputeHash(ByteSourceText)
        'And convert it to String format for return
        Return Convert.ToBase64String(ByteHash)
    End Function


my issue is that each of the codes is returning different value. for example 'yasser' in sql server will be '0x84151990D90822728244C413CB91B9D4' and in vb.net will be 'pTs3IhvbAL8Z3rVn0p/WCw=='

any help in this is highly appreciated

Answer : Diffrent vb.net and Sql Server MD5 hashing

Try casting it the column/variable as NVARCHAR

set @bin = HASHBYTES('MD5', cast(password_temp as nvarchar))
Random Solutions  
 
programming4us programming4us