Sample code for 30+ languages & platforms
C

Verify a Zip's Password

See more Zip Examples

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

Chilkat C Downloads

C
#include <C_CkZip.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkZip zip;
    BOOL passwordOk;

    success = FALSE;

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

    zip = CkZip_Create();

    // To verify a password for a Zip, the Zip must be opened:
    success = CkZip_OpenZip(zip,"myProtected.zip");
    if (success != TRUE) {
        printf("%s\n",CkZip_lastErrorText(zip));
        CkZip_Dispose(zip);
        return;
    }

    // Set the password to be verified:
    CkZip_putDecryptPassword(zip,"secret");

    passwordOk = CkZip_VerifyPassword(zip);
    if (passwordOk == TRUE) {
        printf("Password is correct.\n");
    }
    else {
        printf("Password is incorrect.\n");
    }

    CkZip_CloseZip(zip);


    CkZip_Dispose(zip);

    }