2024-01-29 21:23:41 +01:00
< div align = "center" >
# salvo-captcha
2024-08-12 22:28:55 +02:00
A captcha middleware for [salvo ](salvo.rs ) framework. With fully customizable captchas generator, storage, and finders
2024-01-29 21:23:41 +01:00
[![salvo-captcha-video ](https://i.suar.me/9NjJ1 )](https://ibb.co/XVRVMZj)
< / div >
2024-08-08 16:51:21 +02:00
## Add to your project
2024-01-29 21:23:41 +01:00
First, add the following to your `Cargo.toml` :
```toml
[dependencies]
2024-08-12 22:28:55 +02:00
salvo-captcha = "0.2"
2024-01-29 21:23:41 +01:00
```
2024-08-12 22:28:55 +02:00
Or use [`cargo add`] to add the dependency to your `Cargo.toml` :
2024-01-29 21:23:41 +01:00
```sh
$ cargo add salvo-captcha
```
2024-08-08 16:51:21 +02:00
## Usage
2024-08-12 22:28:55 +02:00
See the [examples] directory for a complete example. You can also see the implemented generators, storages, and finders in the source code.
2024-01-29 21:23:41 +01:00
2024-08-08 16:51:21 +02:00
## Storage
2024-01-29 21:23:41 +01:00
2024-08-12 22:28:55 +02:00
There is a default storage, which is [`MemoryStorage`] it's a simple in-memory storage. You can implement your own storage by implementing the [`CaptchaStorage`] trait.
### Cacache Storage
A high-performance, concurrent, content-addressable disk cache. The storage is based on [`cacache-rs`] crate. to use it, you need to enable the `cacache-storage` feature.
2024-01-29 21:23:41 +01:00
```toml
[dependencies]
2024-08-12 22:28:55 +02:00
salvo-captcha = { version = "0.2", features = ["cacache-storage"] }
2024-01-29 21:23:41 +01:00
```
2024-08-12 22:28:55 +02:00
## Captcha Finder
We provide fully customizable query parameters, form fields, and headers to find the captcha token and the captcha answer. You can implement your own finder by implementing the [`CaptchaFinder`] trait.
## Captcha Generator
2024-08-12 23:07:55 +02:00
We provide [`SimpleCaptchaGenerator`] which is a simple captcha generator based on the [`captcha`] crate, you can enable it by enabling the `simple-generator` feature.
```toml
[dependencies]
salvo-captcha = { version = "0.2", features = ["simple-generator"] }
```
You can implement your own generator by implementing the [`CaptchaGenerator`] trait.
2024-08-12 22:28:55 +02:00
### Captcha name and difficulty
2024-08-08 16:51:21 +02:00
In this table, you can see the difference between the difficulties and the name of the captcha.
2024-08-12 22:28:55 +02:00
| Name | Easy | Medium | Hard |
| :-------------: | :----------------------------------: | :----------------------------------: | :----------------------------------: |
| Normal | ![Simple ](https://i.suar.me/edwBG/s ) | ![Simple ](https://i.suar.me/NJmg0/s ) | ![Simple ](https://i.suar.me/OJK7M/s ) |
| SlightlyTwisted | ![Simple ](https://i.suar.me/1JaxG/s ) | ![Simple ](https://i.suar.me/l7zBl/s ) | ![Simple ](https://i.suar.me/qXAlx/s ) |
| VeryTwisted | ![Simple ](https://i.suar.me/dO78z/s ) | ![Simple ](https://i.suar.me/PXBwK/s ) | ![Simple ](https://i.suar.me/8edgE/s ) |
2024-08-08 16:51:21 +02:00
## Mirrors
2024-01-29 21:23:41 +01:00
2024-08-12 22:28:55 +02:00
- Github (< https: // github . com / TheAwiteb / salvo-captcha > )
- Codeberg (< https: // codeberg . org / awiteb / salvo-captcha > )
2024-08-08 16:51:21 +02:00
### Main Repository
2024-08-12 22:28:55 +02:00
- My Git (< https: // git . 4rs . nl / awiteb / salvo-captcha > )
2024-08-08 16:51:21 +02:00
## License
2024-08-12 22:28:55 +02:00
This project is licensed under the MIT license for more details see [LICENSE] or < http: / / opensource . org / licenses / MIT > .
2024-01-29 21:23:41 +01:00
2024-08-12 22:28:55 +02:00
[`MemoryStorage`]: https://docs.rs/salvo-captcha/latest/salvo_captcha/struct.MemoryStorage.html
[`CaptchaStorage`]: https://docs.rs/salvo-captcha/latest/salvo_captcha/trait.CaptchaStorage.html
2024-08-08 16:51:21 +02:00
[`cacache-rs`]: https://github.com/zkat/cacache-rs
2024-08-12 22:28:55 +02:00
[`SimpleCaptchaGenerator`]: https://docs.rs/salvo-captcha/latest/salvo_captcha/struct.SimpleCaptchaGenerator.html
[`CaptchaGenerator`]: https://docs.rs/salvo-captcha/latest/salvo_captcha/trait.CaptchaGenerator.html
[`CaptchaFinder`]: https://docs.rs/salvo-captcha/latest/salvo_captcha/trait.CaptchaFinder.html
[examples]: https://git.4rs.nl/awiteb/salvo-captcha/src/branch/master/examples
[`captcha`]: https://github.com/daniel-e/captcha
[LICENSE]: https://git.4rs.nl/awiteb/salvo-captcha/src/branch/master/LICENSE
[`cargo add`]: https://doc.rust-lang.org/cargo/commands/cargo-add.html