Sample code for 30+ languages & platforms
Rust

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

Rust

// Note: Requires Chilkat v9.5.0.77 or greater.

let cert = chilkat::Cert::new();

cert.set_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.
if cert.load_from_smartcard("").is_err() {
    println!("{}", cert.last_error_text());
    return;
}

// Check to see if the SmartCardPin property contains the valid PIN for the smartcard.
let pin_valid = cert.check_smart_card_pin();
if pin_valid < 0 {
    println!("Unable to check the PIN validity.");
    println!("{}", cert.last_error_text());
    return;
}

if pin_valid == 1 {
    println!("PIN is valid.");
} else {
    println!("PIN is invalid.");
}