Sample code for 30+ languages & platforms
PureBasic

Verify a Zip's Password

See more Zip Examples

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

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkZip.pb"

Procedure ChilkatExample()

    success.i = 0

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

    zip.i = CkZip::ckCreate()
    If zip.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; To verify a password for a Zip, the Zip must be opened:
    success = CkZip::ckOpenZip(zip,"myProtected.zip")
    If success <> 1
        Debug CkZip::ckLastErrorText(zip)
        CkZip::ckDispose(zip)
        ProcedureReturn
    EndIf

    ; Set the password to be verified:
    CkZip::setCkDecryptPassword(zip, "secret")

    passwordOk.i
    passwordOk = CkZip::ckVerifyPassword(zip)
    If passwordOk = 1
        Debug "Password is correct."
    Else
        Debug "Password is incorrect."
    EndIf

    CkZip::ckCloseZip(zip)


    CkZip::ckDispose(zip)


    ProcedureReturn
EndProcedure