1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
CREATE OR REPLACE FUNCTION verify_password
(
password varchar2,
username varchar2,
old_password varchar2
)
RETURN BOOLEAN
IS
n BOOLEAN;
presenceChiffre BOOLEAN;
longueurPassword integer;
--listeChiffre varchar2(10);
longueur_insuffisante exception;
chiffre_manquant exception;
password_identique_username exception;
mot_interdit exception;
cursor c1
IS
SELECT 'interdit' as mot
FROM dual
;
BEGIN
longueurPassword:=length(password); /*Variable qui sera utilisé tout au long des traitements*/
/*----------------Traitement de la longueur d'un mot de passe--------------------------------------------------*/
IF longueurPassword < 4 THEN /*La fonction length permet de récupérer la longueur du mot de passe*/
RAISE longueur_insuffisante;
END IF;
/*----------------Traitement du nombre minimum de chiffre------------------------------------------------------*/
/*Déclaration et initialisation des variables*/
-- listeChiffre :='0123456789';
presenceChiffre:=FALSE;
/*Cherche une correspondance entre le mot de passe et la liste de chiffre*/
FOR i IN 0..9
LOOP
IF INSTR(password,i) > 0 THEN
presenceChiffre:=TRUE;
END IF;
END LOOP;
IF NOT presenceChiffre THEN
RAISE chiffre_manquant;
END IF;
/*----------------Fonction qui détermine si le mot de passe est identique au nom d'utilisateur ----------------*/
IF INSTR(lower(password),lower(username) ) > 0 THEN
RAISE password_identique_username;
END IF;
/*----------------Traitement des mots interdits dans le mot de passe ------------------------------------------*/
FOR enreg IN c1 LOOP
IF INSTR(lower(password),lower(enreg.mot)) > 0 THEN
RAISE mot_interdit;
END IF;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Success !!!');
RETURN(TRUE);
EXCEPTION
WHEN longueur_insuffisante THEN
DBMS_OUTPUT.PUT_LINE('Le mot de passe est trop court, il doit contenir au moins 4 caractères');
RETURN(FALSE);
WHEN chiffre_manquant THEN
DBMS_OUTPUT.PUT_LINE('Le mot de passe doit contenir au moins 1 chiffre');
RETURN(FALSE);
WHEN password_identique_username THEN
DBMS_OUTPUT.PUT_LINE('Mot de passe est identique au nom d''utilisateur');
RETURN(FALSE);
WHEN mot_interdit THEN
DBMS_OUTPUT.PUT_LINE('Votre mot de passe contient un mot interdit');
RETURN(FALSE);
END verify_password;
DECLARE
RETOUR BOOLEAN;
BEGIN
RETOUR := verify_password('123','toto','toto02');
RETOUR := verify_password('abcdef','toto','toto02');
RETOUR := verify_password('toto01','toto','toto02');
RETOUR := verify_password('interdit01','toto','toto02');
RETOUR := verify_password('sldfhqs;dfbh01','toto','toto02');
END;
/
DROP FUNCTION verify_password; |
Partager