fjtello / SQL-C-sharp

Common programming and coding tips and howtos
0 stars 0 forks source link

SQL [#password #pwdcompare #varbinary] #39

Open fjtello opened 7 years ago

fjtello commented 7 years ago

DECLARE @password NVARCHAR(MAX); SET @password = 'APassword'; DECLARE @salt VARBINARY(4); SET @salt = CAST(NEWID() AS VARBINARY(4)); DECLARE @hash VARBINARY(MAX);

SET @hash = 0x0100 + @salt + HASHBYTES('SHA1', CAST(@password AS VARBINARY(MAX)) + @salt);

SELECT @salt password, @hash AS HashValue, PWDCOMPARE(@password,@hash) AS IsPasswordHash;

http://sqlity.net/en/2460/sql-password-hash/