I am having trouble writing a stored procedure that first checks a hashed password against a user supplied password (also hashed). If the passwords match the procedure would change the password to a new password that is supplied by the user to be hashed before being stored. I took a stab at it and turned up with the code below that seems to be completely outside of proper syntax. Any help that can be supplied would be much appreciated. The code in question is below:
Create Proc UserChangePassword
@pGuid varchar(50),
@pOldPassword varchar(100),
@pHashedPassword varchar (100),
@pNewPassword varchar(10)
AS
set @pHashedPassword = HASHBYTES('md5', @pOldPassword)
set @pOldPassword as select st01Password from st01UserData where @pGuid = st01GUID
If ( @pOldPassword = @pHashedPassword)
Begin
Update st01UserData (
set st01Password = HASHBYTES('md5', @pNewPassword))
where st01GUID = @pGuid
Return 'SUCCESS'
Else
RETURN 'FAILED'
GO
Some reasons behind your problems:
@pHashedPasswordif you just blindly set it to something as the first line of your procedure?set @variable AS SELECT ...is not valid T-SQL syntax.BEGINdoesn’t have a matchingEND.UPDATE table (is also not valid.RETURNa string, only anINT.Try this version: