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
| SQL> create or replace FUNCTION verify_function
2 (
3 nom varchar2,
4 pwd varchar2,
5 old_pwd varchar2
6 )
7 RETURN boolean is
8 m integer;
9 isdigit boolean;
10 ischar boolean;
11 digitarray varchar2(20);
12 chararray varchar2(52);
13 BEGIN
14 digitarray:='0123456789';
15 chararray:='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
16 --test si le nom est le meme que le mot de passe
17 IF pwd = nom THEN
18 raise_application_error(-20001,'pwd=user');
19 END IF;
20 --test si le mot de passe contient au moins 4 caractère
21 IF length(pwd) < 4 THEN
22 raise_application_error(-20002,'Mot de passe trop court');
23 END IF;
24 --test si le mot de passe est trop simple
25 IF NLS_LOWER(pwd) like ('%tam%') THEN
26 raise_application_error(-20002,'mot de passe trop simple');
27 END IF;
28 IF NLS_LOWER(pwd) like ('%cam%')THEN
29 raise_application_error(-20002,'mot de passe trop simple');
30 END IF;
31 IF NLS_LOWER(pwd) IN ('tente','azer') THEN
32 raise_application_error(-20002,'mot de passe trop simple');
33 END IF;
34 --test si le mot de passe contient un chiffre et une lettre
35 isdigit:=FALSE;
36 m := length(pwd);
37 FOR i IN 1..10 LOOP
38 FOR j IN 1..m LOOP
39 IF substr(pwd,j,1) = substr(digitarray,i,1) THEN
40 isdigit:=TRUE;
41 GOTO findchar;
42 END IF;
43 END LOOP;
44 END LOOP;
45 IF isdigit = FALSE THEN
46 raise_application_error(-20003,'le mot de passe doit contenir un chiffre'
);
47 END iF;
48 <<findchar>>
49 ischar:=FALSE;
50 FOR i IN 1..length(chararray) LOOP
51 FOR j IN 1..m LOOP
52 IF substr(pwd,j,1) = substr(chararray,i,1) THEN
53 ischar:= TRUE;
54 GOTO endsearch;
55 END IF;
56 END LOOP;
57 END LOOP;
58 IF ischar = FALSE THEN
59 raise_application_error(-20003,'le mot de passe doit avoir un chiffre');
60 END IF;
61 <<endsearch>>
62 RETURN(TRUE);
63 end;
64 /
Fonction crÚÚe. |
Partager