Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
ScMinidriver - Change Smart Card PIN (or USB token PIN)
See more ScMinidriver Examples
Demonstrates how to change the PIN for a smart card or USB token.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.ScMinidriver;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
scmd: TScMinidriver;
readerName: string;
currentPin: string;
newPin: string;
retval: Integer;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
scmd := TScMinidriver.Create;
// Reader names (smart card readers or USB tokens) can be discovered
// via List Readers or Find Smart Cards
readerName := 'Alcor Micro USB Smart Card Reader 0';
success := scmd.AcquireContext(readerName);
if (success = False) then
begin
WriteLn(scmd.LastErrorText);
Exit;
end;
// If successful, the name of the currently inserted smart card is available:
WriteLn('Card name: ' + scmd.CardName);
// Change the "user" PIN. (Typically, you'll always be using the "user" PIN.)
currentPin := '0000';
newPin := '1234';
retval := scmd.PinChange('user',currentPin,newPin);
if (retval = -1) then
begin
WriteLn('The PIN is already blocked.');
Exit;
end;
if (retval = -2) then
begin
WriteLn('The PinChange function failed for some unanticipated reason');
WriteLn(scmd.LastErrorText);
Exit;
end;
if (retval = 0) then
begin
WriteLn('PIN successfully changed.');
end
else
begin
WriteLn('Current PIN is incorrect.');
WriteLn('Number of attempts remaining = ' + retval);
end;
scmd.DeleteContext();
scmd.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.