Encrypt and Decrypt Method
-----------------------------------------

CREATE
TABLE #T(ID INT IDENTITY(1,1), PWD VARCHAR(MAX))INSERT INTO #T VALUES(EncryptByPassPhrase('7622','123@2011'))SELECT * FROM #TSELECT
CONVERT(VARCHAR, DECRYPTByPassPhrase('7622', PWD)) FROM#T


'7622' is an ID for getting the encrypted values


pwdencrypt and Pwdcompare -----------------------------


CREATE TABLE #Login(id_num int, pwd varbinary (255))-- encryptiondeclare @hashedValue varbinary (MAX)SET @hashedValue = pwdencrypt('123') INSERT INTO #Login(id_num,pwd) VALUES (1,@hashedValue)SET @hashedValue = pwdencrypt('123')INSERT

INTO #Login (id_num,pwd) VALUES (2,@hashedValue)
declare
@hashedValue varbinary (MAX)SELECT TOP 1 @hashedValue = pwd FROM #Login WHERE id_num = 2-- ComparisonSELECT pwdcompare ('123', @hashedValue) AS [Success of check] SELECT * FROM #Login

INSERT
INTO #Login (id_num,pwd) VALUES (3,CONVERT(varbinary (255),0x01002D60BA07FE612C8DE537DF3BFCFA49CD9968324481C1A8A8FE612C8DE537DF3BFCFA49CD9968324481C1A8A8

))

declare
@hashedValue varbinary (MAX)SELECT TOP 1 @hashedValue = pwd FROM #Login WHERE id_num = 3-- ComparisonSELECT pwdcompare ('123', @hashedValue) AS [Success of check]
SELECT
* FROM #LoginDROP TABLE #Login


Comments (0)