1
Good morning, I’m trying to create a Rigger that generates a random password with uppercase letters and 0-9 numbers in a database password field, as it is possible to do this Rigger ?
[FUNCTION]
CREATE DEFINER=`root`@`localhost` FUNCTION `gerador_senha`() RETURNS char(6) CHARSET utf8
BEGIN
DECLARE Aux VARCHAR(31) DEFAULT '23456789ABCDEFGHJKMNPQRSTUVWXYZ';
DECLARE Result varchar(6) DEFAULT '';
REPEAT
SET Result = CONCAT(Result, SUBSTRING(Aux, FLOOR(RAND() * 31), 1));
UNTIL LENGTH(Result) = 6
END REPEAT;
RETURN Result;
END
[TRIGGER]
CREATE
DEFINER=`root`@`localhost`
TRIGGER `vendas`.`before_funcionarios_insert`
BEFORE UPDATE ON `vendas`.`tb_funcionarios`
FOR EACH ROW
BEGIN
IF (NEW.fun_senha = ' ' or New.fun_senha IS NULL) THEN
SET NEW.fun_senha = gerador_senha();
END IF;
END
Provide more details of the problem and environment (database, tables etc), and probably the best solution will not go through Trigger.
– Motta
question edited with the answer
– Jackson Felipe Magnabosco