Sample code for 30+ languages & platforms
JavaScript

Verify a Zip's Password

See more Zip Examples

Demonstrates how to verify the password for an encrypted or password-protected zip archive.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

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

var zip = new CkZip();

// To verify a password for a Zip, the Zip must be opened:
success = zip.OpenZip("myProtected.zip");
if (success !== true) {
    console.log(zip.LastErrorText);
    return;
}

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

var passwordOk;
passwordOk = zip.VerifyPassword();
if (passwordOk == true) {
    console.log("Password is correct.");
}
else {
    console.log("Password is incorrect.");
}

zip.CloseZip();