#captcha #back-end #hcaptcha #protection #security

macro hcaptcha_derive

Derive macro for hCaptcha. Please use hcaptcha crate.

27 stable releases

new 3.0.0 Dec 9, 2024
2.7.6 Oct 24, 2024
2.5.0 Sep 14, 2024
2.4.4 Jul 27, 2024
2.1.0 Oct 29, 2021

#26 in #protection

Download history 10/week @ 2024-08-21 208/week @ 2024-08-28 206/week @ 2024-09-04 238/week @ 2024-09-11 61/week @ 2024-09-18 1454/week @ 2024-09-25 224/week @ 2024-10-02 185/week @ 2024-10-09 1401/week @ 2024-10-16 1652/week @ 2024-10-23 355/week @ 2024-10-30 531/week @ 2024-11-06 112/week @ 2024-11-13 86/week @ 2024-11-20 164/week @ 2024-11-27 292/week @ 2024-12-04

772 downloads per month
Used in hcaptcha

MIT/Apache

23KB
328 lines

Rust library hcaptcha

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

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

Installation

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

[dependencies]
hcaptcha = "2.8.10"

Breaking changes with version 3.0.0

  • The Hcaptcha prefix has been removed from all types.
  • The default feature now uses rustls-backend and not the nativetls-backend.
  • The verify_client_response method has been deprecated in favour or the verify method.

Usage

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

# use hcaptcha::Hcaptcha;

#[derive(Debug, Deserialize, Hcaptcha)]
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 hcaptcha-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.

Credits

Initial version based on recaptcha-rs by panicbit.

Dependencies

~290–730KB
~17K SLoC