I have a stored procedure along these lines:
CREATE DEFINER=`username`@`localhost` PROCEDURE `UserUpdate`(IN inUserId INT, IN inUserFname VARCHAR(40), IN inUserLname VARCHAR(40), IN inUserEmail VARCHAR(40), IN inUserPhone VARCHAR(40), IN inUserPassword BINARY(60))
BEGIN
IF inUserPassword='' THEN
UPDATE `users`
SET fname=inUserFname, lname=inUserLname, email=inUserEmail, phone=inUserPhone, datemodified=NOW()
WHERE id=inUserId;
ELSE
UPDATE `users`
SET fname=inUserFname, lname=inUserLname, email=inUserEmail, phone=inUserPhone, password=inUserPassword, datemodified=NOW()
WHERE id=inUserId;
END IF;
END
The information is coming from a HTML Form/PHP script. If the user has not updated their password, then the inUserPassword remains blank and IF
portion of the procedure should run. If the user has updated their password in the form, then the ELSE
portion should run.
The password is stored as a bcrypt hash and the column in the database is set as BINARY(60).
The problem that I'm running into is that I can't trigger the IF
if the BINARY is used for the password. If I change the password column to VARCHAR, the above query works just fine. I understand that the binary value is not the same as ASCII or Unicode value, but for nothing, as in the above code, shouldn't it be the same?
How should I go about fixing it? Thanks for any help.