I want to implement a password encryption system using SQL in SQL Server 2012.
The HASHBYTES
method must have only nvarchar
, varbinary
datatype.
update members
set passwd = cast(HASHBYTES('SHA2_256', 'asd123123') as varchar(256)),
pwchangedat = GETDATE()
where userid = 'abcd1234'
The unexpected result of the Select
query applied above update query:
?lZX?갅4磎?닽뙷?I?#?뚭?
I want to fix this varchar(256)
data type string 'asd123123' applied SHA-256 encryption.
I want:
c82a6c7f5a58a915814334cda5a2ef88ab8cba922f49ec1623e2248ceabf7ddc
How can I get a solution?
Regards,
I think this is what you are looking for...
select convert(varchar(256),HASHBYTES('SHA2_256','asd123123'),2)
See the Binary Styles Section (since Hashbytes returns varbinary)
Thus....
update members set
passwd = convert(varchar(256),HASHBYTES('SHA2_256','asd123123'),2),
pwchangedat = GETDATE()
where userid = 'abcd1234'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With