I have a use case in which I have to get last five password from passwordhistory table,and there two column one md5 encrypted and second is hash ,after retrieving five records then I have to compared these column with new password,after moving them from md5 and hash function,if any record found then return true else return false.
Code
DECLARE @UserID INT = 6Code
DECLARE @Password NVARCHAR(200)='admin1952'Code
SELECT * FROMCode
( SELECT TOP 5Code
ChangedPassword AS ChangedPassword ,Code
PasswordChangeHistory.Password_Hash AS Password_HashCode
FROM PasswordChangeHistory WITH ( NOLOCK )Code
INNER JOIN [User] U WITH ( NOLOCK )Code
ON PasswordChangeHistory.UserID = U.IdCode
WHERE PasswordChangeHistory.UserID = @UserIDCode
) AS resultCode
WHERE PasswordChangeHistory.ChangedPassword = dbo.Encrypt_MD5(@Password)Code
OR PasswordChangeHistory.Password_Hash = dbo.Encrypt_SHA2(@Password)

Sajid HussainRank #3,026 · 476 reputationPosted May 9, 2017, 10:22 PM EDT