18 个版本 (稳定版)
新版本 2.4.7 | 2024年8月17日 |
---|---|
2.4.4 | 2024年7月27日 |
2.3.1 | 2024年1月27日 |
2.2.2 | 2023年4月9日 |
0.4.0 | 2020年11月23日 |
#197 in 网页开发
每月下载量 745
110KB
1.5K SLoC
Rust 库 hcaptcha
rust 库 hcaptcha 用于与您的后端服务配合使用,以验证客户端提供的 hcaptcha 响应。
安装
要在项目中使用 hcaptcha-rs,您可以将以下内容添加到您的 Cargo.toml
[dependencies]
hcaptcha = "2.4.7"
用法
在表示您数据的结构体上派生验证方法,标记数据结构中的验证码组件。
# use hcaptcha::Hcaptcha;
#[derive(Debug, Deserialize, Hcaptcha)]
pub struct ContactForm {
name: String,
phone: String,
email: String,
message: String,
#[captcha]
token: String,
}
验证验证码数据。
# #[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()
# }
请参阅示例文件夹中的 AWS Lambda 联系表单示例。
许可协议
根据您的选择,受以下任一许可协议的约束:
- Apache License,版本 2.0 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT 许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
第三方许可协议
第三方许可协议的总结可以在 此处 找到
贡献
除非您明确声明,否则您提交给工作内容的任何贡献,根据 Apache-2.0 许可协议定义,应作为上述双重许可,不附加任何其他条款或条件。
鸣谢
初始版本基于 panicbit 的 recaptcha-rs。
依赖项
~4–16MB
~255K SLoC