I am modifying an application that uses the PWDEncrypt and PWDCompare functions of SQL Server to store hashed passwords into a varbinary column of a table.
As these functions should not be used (due to possible changes in the algorithm or they become deprecated in the future) I would like to convert the application to use the supported HASHBYTES function instead.
Does anyone have the code to implement the same functionality as PWDENCRYPT/PWDCOMPARE using the HASHBYTES functionality so that I do not have to get every user to change their password during the change over and the existing hashed passwords remain valid?
I am using SQL Server 2008 R2.
I have managed to produce my own implementation of PWDENCRYPT and PWDCOMPARE using just SQL.
Unfortunately, due to the use of RAND() in the PWDENCRYPT section you cannot convert this to a UDF.
This is the code that performs the PWDEncrypt
This is the code that performs the PWDCompare