Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
declare @original nvarchar(128)  = '1'
declare @afterhash varbinary(128) = HASHBYTES('SHA2_512', '1')

select PWDCOMPARE(@original, @afterhash)
select @afterhash


What I have tried:

I have tried to change 1 to 0 and change 1 to @original.
Posted
Updated 9-Nov-17 6:32am

1 solution

It's returning 0 because PWDCOMPARE is hashing the clear text password you're passing in with an algorithm that is not SHA2_512.

You can see this yourself by doing this:
DECLARE @Original nvarchar(128) = '1';

DECLARE @Hashed varbinary(128) = HASHBYTES('SHA2_512', '1');

SELECT PWDENCRYPT(@Original) AS 'PWDENCRYPT Hash';
SELECT @Hashed AS 'SHA2_512 Hash';

SELECT PWDCOMPARE(@Original, @Hashed);


You should only use PWDCOMPARE with a column that was encrypted with PWDENCRYPT.

You should NOT being PWDENCRYPT anymore. Use HASHBYTES instead and compare against the column value yourself.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900