I have this query:
declare @password nvarchar(254) ='R0nald0$123456.',
@username nvarchar(50)='Ronaldo',
@playerId uniqueidentifier,
@userType int;
declare @UserUsername_CS int =CHECKSUM(@username);
SELECT Top 1 @playerId = [UserId]
FROM [dbo].[UsersPrivate]
WHERE [UserUsername_CS] = @UserUsername_CS
And [UserUsername] = @username
AND [UserPassword] = HASHBYTES('SHA2_256', CONCAT([Salt], @password));
select @playerId
It generates the right result; however, I am not sure I am using the “best way” to do this when comparing the user’s password with the provided password via the hash.
As [Salt] is part of the table, I can’t pre-glue them to get a Binary(32) variable. I have the following index:
CREATE UNIQUE INDEX [IX_UsersPrivate_UserName_UserPassword] ON [dbo].[UsersPrivate]
(
[UserUsername_CS] ASC,
[UserUsername] ASC,
[UserPassword] ASC
)
, which is ignored by the execution plan.
Type conversion in expression (CONVERT_IMPLICIT(nvarchar(8),
[ClubStat].[dbo].[UsersPrivate].[Salt],0)) may affect
“CardinalityEstimate” in query plan choice
Here is the execution plan: Past the plan