Zig
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// Note: Requires Chilkat v9.5.0.77 or greater.
const cert = try chilkat.Cert.init();
defer cert.deinit();
cert.setSmartCardPin("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.
cert.loadFromSmartcard("") catch {
std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
return;
};
// Check to see if the SmartCardPin property contains the valid PIN for the smartcard.
const pin_valid = cert.checkSmartCardPin();
if (pin_valid < 0) {
std.debug.print("Unable to check the PIN validity.\n", .{});
std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
return;
}
if (pin_valid == 1) {
std.debug.print("PIN is valid.\n", .{});
} else {
std.debug.print("PIN is invalid.\n", .{});
}
}