Skip to content

Instantly share code, notes, and snippets.

@sagarPakhrin
Created January 22, 2020 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagarPakhrin/094c865a9f6ed112d6192d9c3906fe2d to your computer and use it in GitHub Desktop.
Save sagarPakhrin/094c865a9f6ed112d6192d9c3906fe2d to your computer and use it in GitHub Desktop.

DROP TRIGGER IF EXISTS upd_user;

DELIMITER $$

CREATE TRIGGER upd_user BEFORE UPDATE ON `user`
FOR EACH ROW BEGIN
  IF (NEW.password IS NULL OR NEW.password = '') THEN
        SET NEW.password = OLD.password;
  ELSE
        SET NEW.password = Password(NEW.Password);
  END IF;
END$$

DELIMITER ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment