(C) Verify a Zip's Password
Demonstrates how to verify the password for an encrypted or password-protected zip archive.
#include <C_CkZip.h>
void ChilkatSample(void)
{
HCkZip zip;
BOOL success;
BOOL passwordOk;
// 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);
}
|