Sample code for 30+ languages & platforms
VB.NET

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 VB.NET Downloads

VB.NET
Dim success As Boolean = False

' Note: Requires Chilkat v9.5.0.77 or greater.

Dim cert As New Chilkat.Cert

cert.SmartCardPin = "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 = cert.LoadFromSmartcard("")
If (success <> True) Then
    Debug.WriteLine(cert.LastErrorText)
    Exit Sub
End If


' Check to see if the SmartCardPin property contains the valid PIN for the smartcard.
Dim pinValid As Integer = cert.CheckSmartCardPin()
If (pinValid < 0) Then
    Debug.WriteLine("Unable to check the PIN validity.")
    Debug.WriteLine(cert.LastErrorText)
    Exit Sub
End If


If (pinValid = 1) Then
    Debug.WriteLine("PIN is valid.")
Else
    Debug.WriteLine("PIN is invalid.")
End If