2 releases

0.1.2 May 15, 2025
0.1.0 Dec 23, 2024

#996 in Web programming

Download history 3/week @ 2025-02-05 9/week @ 2025-02-19 8/week @ 2025-02-26 8/week @ 2025-04-16 152/week @ 2025-05-14

152 downloads per month

MIT/Apache

130KB
2K SLoC

Rust library captval

Crates.io MIT licensed Build Status Rust 1.81+ Docs BuyMeaCoffee GitHubSponsors codecov

The rust library captval is used with your backend service to verify the captval response provided from the client.

Installation

To use captval, add the following to your Cargo.toml:

[dependencies]
captval = "0.1.2"

Usage

Derive a validation method on the data structure representing your data, marking the captcha components in the data structure.

# use captcha::Captcha;

#[derive(Debug, Deserialize, Captcha)]
pub struct ContactForm {
    name: String,
    phone: String,
    email: String,
    message: String,
    #[captcha]
    token: String,
}

Validate the captcha data.

    # #[tokio::main]
    # async main() -> Result<(), Box<dyn std::error::Error>> {
    let contact_form: ContactForm = serde_json::from_str(e.body_string())?;
    contact_form.valid_response(&secret, None).await?;
    # }
    # fn get_your_secret() -> String {
    #   "0x123456789abcde0f123456789abcdef012345678".to_string()
    # }

See the examples folder for an AWS Lambda contact form example.

Web Assembly

Hcaptcha has been tested in a web assembly project using wasm-bindgen and node.

See the captval-wasm example for a sample project which can be run using wasm-pack test --node.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~5–18MB
~248K SLoC