Hashbytes comparison in stored proceduring not matching record
The password field in my user table (SQL Server 2008) is encrypted using HASHBYTES
on insertion. I have a stored procedure with parameters for the username and plain-text password whi开发者_开发知识库ch does a SELECT
using that username and the password sent through HASHBYTES
, then returns the user record if it finds a match. The SP is always returning an empty recordset, but if I copy and paste just the SELECT
from the SP to a new query window, it returns the matched record. There're no other statements in the SP. I'm missing something here; what is it?
If the SELECT on its own works, but inside the procedure it does not, the first thing I would look for is parameter types. Hash will vary wildly on similar input, but different types:
select hashbytes('MD5','Lorem Ipsum'), hashbytes('MD5',N'Lorem Ipsum')
How are you passing in the parameters when calling it from your code? Are there any embedded CR/LF or whitespace?
精彩评论