Hashbytes in SQL Server returns different value for different data type

If you are using Hashbytes ‘SHA1’ or ‘MD5’ algorithm for your password field make sure you are not changing database in insert procedure and select procedure otherwise you will not be able to find any error and also won’t be able to get desired output.

Following is the example

declare @str1 as varchar(15)
declare @str2 as nvarchar(15)

set @str1 = ‘javadotnet’
set @str2 = ‘javadotnet’

hashbytes(‘md5’, @str1) as ‘varchar’,
hashbytes(‘md5’, @str2) as ‘nvarchar’,
hashbytes(‘md5’, ‘javadotnet’) as ‘default’

hashbytes(‘sha1’, @str1) as ‘varchar’,
hashbytes(‘sha1’, @str2) as ‘nvarchar’,
hashbytes(‘sha1’, ‘javadotnet’) as ‘default’

Leave a Reply

Your email address will not be published.