Monday, April 19, 2010

MD5 Password in Database(SQL Server 2005) itself

Some of us want some time to encrypt the password in database itself due to security reason.(i.e. At the time of user creation, forgot password or may be at the time of reset the password). So SQL Server also provide the utility for 'MD5 Algorithms' HashBytes() is the function used for encryption more on HashBytes()



select HashBytes('MD5','ABC123');


it will return the varbinary (maximum 8000 bytes)
the output will be '0xBBF2DEAD374654CBB32A917AFD236656'
but it will not equate the value with .NET hashing so to make it equal to .NET Hashing need to use another conversion function with triming the first to '0x'
characters from the returned value like:



select SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes('MD5', 'ABC123')), 3, 32);



and the now the output is 'bbf2dead374654cbb32a917afd236656' that is equal to .NET Hashing techniques




No comments:

Post a Comment