Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Generating Random Password
See more PRNG Examples
Demonstrates how to generate random passwords.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Prng;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
fortuna: TPrng;
bDigit: Boolean;
bUpperAndLower: Boolean;
otherChars: string;
excludeChars: string;
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 := TPrng.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
WriteLn(fortuna.RandomPassword(8,bDigit,bUpperAndLower,otherChars,excludeChars));
end;
fortuna.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.