Advertisement
jacknpoe

CURTA: função SHA2 do MySQL

Jan 26th, 2024 (edited)
1,185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.59 KB | Source Code | 0 0
  1. # INCLUI UM USUÁRIO
  2. INSERT INTO usuario (s_nome, b_senha) VALUES (nome, SHA2(senha, 256));
  3.  
  4. _____________________________________________________________________________________________________________________________
  5.  
  6.  
  7. # RETORNA 1 SE A SENHA É CORRETA, 0 SE INCORRETA
  8. DELIMITER |
  9. CREATE OR REPLACE FUNCTION compararSenha(codigo INTEGER, senha VARCHAR(100)) RETURNS TINYINT DETERMINISTIC
  10. BEGIN
  11.     DECLARE senhaRecuperada CHAR(64);
  12.  
  13.     SELECT b_senha INTO senhaRecuperada FROM usuario WHERE n_codigo = codigo;
  14.  
  15.     Return IF(senhaRecuperada IS NULL, 0, SHA2(senha, 256) = senhaRecuperada);
  16. END |
  17.  
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement