type TCharRange = ( crNumeric, crMinAlpha, crMajAlpha ); TCharRanges = set of TCharRange; function StrShuffle(const S : string): string; var I, NI, L : integer; pR : PChar; begin L := length(S); SetLength(Result, L); pR := PChar(Result); FillChar(pR^, L, #0); for I := 1 to L do begin repeat NI := random(L); until pR[NI] = #0; pR[NI] := S[I]; end; end; { GenPassword Génère un mot de passe aléatoire. Paramètres : LN [I] entier, taille du mot de passe a générer CR [I] TCharRanges, type de caractères présent dans le mots de passe Retour : Chaine, mot de passe généré. } function GenPassword(const LN: integer; const CR: TCharRanges = [crNumeric, crMinAlpha]): string; var safeCR : TCharRanges; safeLN : integer; spwd : string; lpwd : integer; begin spwd := ''; lpwd := 0; safeCR := CR; if safeCR = [] then safeCR := [crNumeric, crMinAlpha]; safeLN := LN; if safeLN = 0 then safeLN := 8; if crNumeric in safeCR then begin spwd := StrShuffle('09182736455463728190'); inc(lpwd,20); end; if crMinAlpha in safeCR then begin spwd := StrShuffle(spwd+'lmnopqrstuvwxyzabcdefghijk'); inc(lpwd,26); end; if crMajAlpha in safeCR then begin spwd := StrShuffle(spwd+'HIJKLMNOPQRSTUVWXYZABCDEFG'); inc(lpwd,26); end; result := copy(StrShuffle(spwd), random(lpwd)-SafeLN, SafeLn); end;
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.