SQL Server: How to retrieve actual value of password encrypted using HASHBYTES

radha singh picture radha singh · Feb 16, 2016 · Viewed 7.6k times · Source

enter image description here

insert into Customer(AccountNo,Name,EmailId,MobileNo,[Password],Balance,
                     CustomerKey,OTPPin,CreatedBy,CreatedOn)
values(@AccountNumber,@Name,@EmailId,
       EncryptByPassPhrase(@PassPhrase, CONVERT(nvarchar,@MobileNo)),
       HASHBYTES('SHA1',@Password),@TotalBalance,@CustomerKey,@OTPPin,0,GETDATE())

I am getting inserted value in this formenter image description here

Now I want the password's actual value. How can I get it?

Answer

Andrey Korneyev picture Andrey Korneyev · Feb 16, 2016

Since you've used HASHBYTES('SHA1' on your password - you can't straightforward get back its original value.

SHA1 is one-way hash function.

In fact, you don't need that original value in most cases. Typical usage of hased passwords is not to somehow get original value from hash and compare it with password entered by user, but instead apply hash function to the password entered by user and then compare two hash values.