CREATE OR REPLACE FUNCTION office.hash_password()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
DECLARE _password text;
DECLARE _is_sys boolean;
BEGIN
_is_sys := office.is_sys_user(NEW.user_id);
_password := encode(digest(NEW.user_name || NEW.password, 'sha512'), 'hex');
IF(NOT _is_sys) THEN
UPDATE office.users
SET password = _password
WHERE office.users.user_name=NEW.user_name;
END IF;
RETURN new;
END
$function$