| Crates.io | altcha-lib-rs |
| lib.rs | altcha-lib-rs |
| version | 0.2.0 |
| created_at | 2024-08-21 20:42:07.087167+00 |
| updated_at | 2025-08-23 20:59:09.212102+00 |
| description | Community implementation of the Altcha library in Rust for your own server application to create and validate challenges and responses. |
| homepage | |
| repository | https://github.com/jmic/altcha-lib-rs |
| max_upload_size | |
| id | 1346909 |
| size | 87,581 |
Community implementation of the ALTCHA library in Rust for your own server application to create and validate challenges and responses.
For more information about ALTCHA https://altcha.org/docs
Not part of this library:
[dependencies]
altcha-lib-rs = { version = "0", features = ["json"] } # with SHA1: ["json", "sha1"]
use altcha_lib_rs::{create_challenge, verify_json_solution,
Payload, Challenge, ChallengeOptions};
fn main() {
// create a challenge
let challenge = create_challenge(ChallengeOptions {
hmac_key: "super-secret",
expires: Some(Utc::now() + chrono::TimeDelta::minutes(1)),
..Default::default()
}).expect("should be ok");
// transmit the challenge to the client and let the client solve it
let res = solve_challenge(&challenge.challenge, &challenge.salt, None, None, 0)
.expect("need to be solved");
// pack the solution into a json string
let payload = Payload {
algorithm: challenge.algorithm,
challenge: challenge.challenge,
number: res,
salt: challenge.salt,
signature: challenge.signature,
took: None,
};
let string_payload = serde_json::to_string(&payload).unwrap();
// receive the solution from the client and verify it
verify_json_solution(&string_payload, "super-secret", true).expect("should be verified");
}