Sample code for 30+ languages & platforms
Lua Requires Chilkat v9.5.0.77+

Validate a Smartcard PIN

See more Certificates Examples

Validates a smartcard PIN.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local cert = chilkat.Cert.new()

cert.smart_card_pin = "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.
local success = cert:load_from_smartcard("")
if not success then
    print(cert.last_error_text)
    return
end

-- Check to see if the SmartCardPin property contains the valid PIN for the smartcard.
local pinValid = cert:check_smart_card_pin()
if pinValid < 0 then
    print("Unable to check the PIN validity.")
    print(cert.last_error_text)
    return
end

if pinValid == 1 then
    print("PIN is valid.")
else
    print("PIN is invalid.")
end