This code is useful when encrypting sensitive data (like passwords) into a varbinary. The PWDENCRYPT and PWDCOMPARE functions are used to encrypt and compare DATA passwords are not visible in anywhere in the database.
-- How to use PWDENCRYPT and PWDCOMPARE declare @pwd varbinary (128) Create table users ( userid int identity (1,1) not null, pswd varbinary (128)) -- INSERTING ENCRYPED value -- hard coded string should be replace -- by a text box value from screen Insert into users values (PWDENCRYPT ('eli leiba')) -- the dencryption phase select @pwd = pswd from users where userid = 1 -- comparing : 1 is success, 0 is not select PWDCOMPARE ('eli leiba',@pwd)
For More Information
- What do you think about this tip? E-mail the Editor at firstname.lastname@example.org with your feedback.
- The Best SQL Server Web Links: tips, tutorials, scripts, and more.
- Have an SQL Server tip to offer your fellow DBA's and developers? The best tips submitted will receive a cool prize--submit your tip today!
- Ask your technical SQL Server questions--or help out your peers by answering them--in our live discussion forums.
- Check out our Ask the Experts feature: Our SQL, Database Design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.