Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

# Note: Requires Chilkat v9.5.0.77 or greater.

set cert [new_CkCert]

CkCert_put_SmartCardPin $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.
set success [CkCert_LoadFromSmartcard $cert ""]
if {$success != 1} then {
    puts [CkCert_lastErrorText $cert]
    delete_CkCert $cert
    exit
}

# Check to see if the SmartCardPin property contains the valid PIN for the smartcard.
set pinValid [CkCert_CheckSmartCardPin $cert]
if {$pinValid < 0} then {
    puts "Unable to check the PIN validity."
    puts [CkCert_lastErrorText $cert]
    delete_CkCert $cert
    exit
}

if {$pinValid == 1} then {
    puts "PIN is valid."
} else {
    puts "PIN is invalid."
}


delete_CkCert $cert