Validate password in stored procedure
passwords, sql, sql-server-2008, stored-procedures
Solution
Your variable @fPassword is NVARCHAR. When you hardcode the string, it is of type VARCHAR. If you put an 'N' before the string, as in "N'sharingan1'", they should be equivalent, as this expresses the string as a NVARCHAR. Or you could make your variable be of type VARCHAR.
Encoding matters.
Problem
I'm having trouble with validating an account in a SQL Server stored procedure. What I do is that I Hashbyte the password of the user. When he wants to log in into his account I again hashbyte the parameter(`@fPassword`) and compare it with the hashbyte password that is in the database. The problem is that I keep getting a different value. For example: ``` declare @fPassword nvarchar(4000) set @fPassword = 'sharingan1' IF (CONVERT(NVARCHAR(4000), HASHBYTES('sha1', @fPassword), 1)) <> (select fPassword from CustomerTable WHERE fUserName = 'cesark14') BEGIN print 'b' END else print 'c' ``` I keep getting `'b'`. But when I replace the `@fPassword` for `'sharingan1'`, I get `'c'`(which is what I want). Does anybody know why is the ``` (CONVERT(NVARCHAR(4000), HASHBYTES('sha1', @fPassword), 1)) ``` where I set `@fPassword = 'sharingan1'` different than ``` (CONVERT(NVARCHAR(4000), HASHBYTES('sha1', 'sharingan1'), 1)) ```