Sample code for 30+ languages & platforms
PureBasic

Validate a Smartcard PIN

See more Certificates Examples

Validates a smartcard PIN. This example only runs on Windows and requires Chilkat v9.5.0.77 or greater.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkCert.pb"

Procedure ChilkatExample()

    success.i = 0

    ; Note: Requires Chilkat v9.5.0.77 or greater.

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

    CkCert::setCkSmartCardPin(cert, "000000")

    ; Load the certificate on the smartcard currently in the reader (or on the USB token).
    ; Pass an empty string to allow Chilkat to automatically choose the CSP (Cryptographi Service Provider).
    ; See Load Certificate on Smartcard for information about explicitly selecting a particular CSP.
    success = CkCert::ckLoadFromSmartcard(cert,"")
    If success <> 1
        Debug CkCert::ckLastErrorText(cert)
        CkCert::ckDispose(cert)
        ProcedureReturn
    EndIf

    ; Check to see if the SmartCardPin property contains the valid PIN for the smartcard.
    pinValid.i = CkCert::ckCheckSmartCardPin(cert)
    If pinValid < 0
        Debug "Unable to check the PIN validity."
        Debug CkCert::ckLastErrorText(cert)
        CkCert::ckDispose(cert)
        ProcedureReturn
    EndIf

    If pinValid = 1
        Debug "PIN is valid."
    Else
        Debug "PIN is invalid."
    EndIf



    CkCert::ckDispose(cert)


    ProcedureReturn
EndProcedure