Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Verify a Zip's Password
See more Zip Examples
Demonstrates how to verify the password for an encrypted or password-protected zip archive.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.Zip;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
zip: TZip;
passwordOk: Boolean;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
zip := TZip.Create;
// To verify a password for a Zip, the Zip must be opened:
success := zip.OpenZip('myProtected.zip');
if (success <> True) then
begin
WriteLn(zip.LastErrorText);
Exit;
end;
// Set the password to be verified:
zip.DecryptPassword := 'secret';
passwordOk := zip.VerifyPassword();
if (passwordOk = True) then
begin
WriteLn('Password is correct.');
end
else
begin
WriteLn('Password is incorrect.');
end;
zip.CloseZip();
zip.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.