Sample code for 30+ languages & platforms
Delphi DLL

Generating Random Password

See more PRNG Examples

Demonstrates how to generate random passwords.

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Prng;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
fortuna: HCkPrng;
bDigit: Boolean;
bUpperAndLower: Boolean;
otherChars: PWideChar;
excludeChars: PWideChar;
i: Integer;

begin
success := False;

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

success := False;

fortuna := CkPrng_Create();

// Set this equal to True if the generated password must include at least one digit (0-9)
bDigit := True;

// Set this equal to True if the generated password must include both uppercase and lowercase chars.
bUpperAndLower := True;

// The generated password must contain one of the following non-alphanumeric chars.
otherChars := '@#$%*';

// Exclude chars that appear similar to others:
excludeChars := 'iIlLoO0';

// Generate 8-character passwords:

for i := 1 to 10 do
  begin
    Memo1.Lines.Add(CkPrng__randomPassword(fortuna,8,bDigit,bUpperAndLower,otherChars,excludeChars));
  end;

CkPrng_Dispose(fortuna);

end;