A stored procedure that first matches the password, then changes it

I am having trouble recording a stored procedure that first checks the hashed password for the password provided by the user (also the hashed one). If the passwords match, the procedure will change the password to a new password, which will be provided by the user for hashing before saving. I took a hit on him and included the code below, which seems completely outside the correct syntax. Any help that could be delivered would be greatly appreciated. Below is the code:

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
+3
source share
1 answer

Some causes of your problems:

  • @pHashedPassword, ?
  • set @variable AS SELECT ... T-SQL.
  • BEGIN END.
  • UPDATE table ( .
  • , , , , .
  • RETURN , INT.
  • , 100 , - 10?

:

CREATE PROCEDURE dbo.UserChangePassword
  @pGuid        VARCHAR(50),
  @pOldPassword VARCHAR(100),
  @pNewPassword VARCHAR(10)
AS
BEGIN
  SET NOCOUNT ON;

  UPDATE dbo.st01UserData
    SET st01Password = HASHBYTES('md5', @pNewPassword)
    WHERE st01Guid = @pGuid
    AND st01Password = HASHBYTES('md5', @pOldPassword);

  IF @@ROWCOUNT = 0
    RETURN -1;

  RETURN 0;
END
GO 
+6

All Articles