Sample code for 30+ languages & platforms
Delphi ActiveX

Verify a Zip's Password

See more Zip Examples

Demonstrates how to verify the password for an encrypted or password-protected zip archive.

Chilkat Delphi ActiveX Downloads

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

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Integer;
zip: TChilkatZip;
passwordOk: Integer;

begin
success := 0;

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

zip := TChilkatZip.Create(Self);

// To verify a password for a Zip, the Zip must be opened:
success := zip.OpenZip('myProtected.zip');
if (success <> 1) then
  begin
    Memo1.Lines.Add(zip.LastErrorText);
    Exit;
  end;

// Set the password to be verified:
zip.DecryptPassword := 'secret';

passwordOk := zip.VerifyPassword();
if (passwordOk = 1) then
  begin
    Memo1.Lines.Add('Password is correct.');
  end
else
  begin
    Memo1.Lines.Add('Password is incorrect.');
  end;

zip.CloseZip();
end;