Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Validate a Smartcard PIN
See more Certificates Examples
Validates a smartcard PIN. This example only runs on Windows and requires Chilkat v9.5.0.77 or greater.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.Cert;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
cert: TCert;
pinValid: Integer;
begin
success := False;
// Note: Requires Chilkat v9.5.0.77 or greater.
cert := TCert.Create;
cert.SmartCardPin := '000000';
// Load the certificate on the smartcard currently in the reader (or on the USB token).
// Pass an empty string to allow Chilkat to automatically choose the CSP (Cryptographi Service Provider).
// See Load Certificate on Smartcard for information about explicitly selecting a particular CSP.
success := cert.LoadFromSmartcard('');
if (success <> True) then
begin
WriteLn(cert.LastErrorText);
Exit;
end;
// Check to see if the SmartCardPin property contains the valid PIN for the smartcard.
pinValid := cert.CheckSmartCardPin();
if (pinValid < 0) then
begin
WriteLn('Unable to check the PIN validity.');
WriteLn(cert.LastErrorText);
Exit;
end;
if (pinValid = 1) then
begin
WriteLn('PIN is valid.');
end
else
begin
WriteLn('PIN is invalid.');
end;
cert.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.