Rust
Rust
ScMinidriver - Change Smart Card PIN (or USB token PIN)
See more ScMinidriver Examples
Demonstrates how to change the PIN for a smart card or USB token.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let scmd = chilkat::ScMinidriver::new();
// Reader names (smart card readers or USB tokens) can be discovered
// via List Readers or Find Smart Cards
let reader_name = "Alcor Micro USB Smart Card Reader 0".to_string();
if scmd.acquire_context(&reader_name).is_err() {
println!("{}", scmd.last_error_text());
return;
}
// If successful, the name of the currently inserted smart card is available:
println!("Card name: {}", scmd.card_name());
// Change the "user" PIN. (Typically, you'll always be using the "user" PIN.)
let current_pin = "0000".to_string();
let new_pin = "1234".to_string();
let retval = scmd.pin_change("user", ¤t_pin, &new_pin);
if retval == -1 {
println!("The PIN is already blocked.");
return;
}
if retval == -2 {
println!("The PinChange function failed for some unanticipated reason");
println!("{}", scmd.last_error_text());
return;
}
if retval == 0 {
println!("PIN successfully changed.");
} else {
println!("Current PIN is incorrect.");
println!("Number of attempts remaining = {}", retval);
}
let _ = scmd.delete_context();