Bonjour,
Comment imposer dans la saisie d'un mot de passe la présence de caractères spéciaux, caractères numeriques, caracteres majuscule, et caracteres minuscule.
Merci
Bonjour,
Comment imposer dans la saisie d'un mot de passe la présence de caractères spéciaux, caractères numeriques, caracteres majuscule, et caracteres minuscule.
Merci
Cela ne doit pas bien être compliqué
Dans le OnExit ou dans un bouton Valider, tu appels une fonction, si elle échoue tu force le focus sur le champ PW
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 function IsComplexPassWord(const S: string): Boolean; const SPECIAUX: array[1..3] of char = ('+', '#', '*'); ACCENTS: array[..] of char = ('é', 'ù' ...); var HaveNumeric ... : Boolean; begin ... init ... for I := 1 to Length(S) do begin if S[i] in ['0'..'9'] then HaveNumeric := true; if S[i] in ['a'..'z'] then HaveMin := true; if S[i] in ['A'..'Z'] then HaveMaj := true; for k := Low(SPECIAUX) to High(SPECIAUX) if S[i] = SPECIAUX[k] then HaveSpe := true; for k := Low(ACCENTS) to High(ACCENTS) if S[i] = ACCENTS[k] then HaveAcc := true; end; Result := HaveNumeric and HaveMin ... end;
Merci beaucoup.
Surtout en utilisant l'evenement OnChange de ton TEdit/TMaskEdit qui permettra de verifier à la volée :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 type TPWCharSpace = packed record chars : string; min : integer; end; const CS_AlphaLow : TPWCharSpace = (chars: 'abcdefghjkmnpqrstuvwxyz'; min: 2); CS_AlphaUp : TPWCharSpace = (chars: 'ABCDEFGHJKMNPQRSTUVWXYZ'; min: 1); CS_Numeric : TPWCharSpace = (chars: '23456789'; min: 2); CS_Specials : TPWCharSpace = (chars: '#~^@_-.'; min: 0); CS_Excluded : TPWCharSpace = (chars: 'iI1lLoO0'; min: -1); function TestCharSpace(aStr: string; aCharSpace: TPWCharSpace): boolean; var C,X: integer; begin C := 0; for X := 1 to Length(aStr) do if pos(aStr[X], aCharSpace.chars) <> 0 then inc(c); if aCharSpace.min < 0 then result := C = 0 else result := C >= aCharSpace.min; end; function IsValidPW(aPW : string; aMinLength, aMaxLength: integer): boolean; var N, L : integer; begin L := Length(aPW); result := (L >= aMinLength) and (L <= aMaxLength); if result then result := TestCharSpace(aPW, CS_AlphaLow) and TestCharSpace(aPW, CS_AlphaUp) and TestCharSpace(aPW, CS_Numeric) and TestCharSpace(aPW, CS_Specials) and TestCharSpace(aPW, CS_Excluded); end; procedure TForm5.EditPWChange(Sender: TObject); var B: boolean; const PWC: array[boolean] of TColor= (clRed, clGreen); begin B := IsValidPW(EditPW.Text, 6, 16); EditPW.Font.Color := PWC[B]; BtnContinue.Enabled := B; end;
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager