Expand description
§salvo-captcha
A captcha middleware for salvo framework. With fully customizable captchas generator, storage, and finders
§Add to your project
First, add the following to your Cargo.toml:
[dependencies]
salvo-captcha = "0.4"Or use cargo add to add the dependency to your Cargo.toml:
$ cargo add salvo-captcha§Usage
See the examples directory for a complete example. You can also see the implemented generators, storages, and finders in the source code.
§Storage
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.
[dependencies]
salvo-captcha = { version = "0.3", features = ["cacache-storage"] }§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
We provide SimpleCaptchaGenerator which is a simple captcha generator based on the captcha crate, you can enable it by enabling the simple-generator feature.
[dependencies]
salvo-captcha = { version = "0.3", features = ["simple-generator"] }You can implement your own generator by implementing the CaptchaGenerator trait.
§Captcha name and difficulty
In this table, you can see the difference between the difficulties and the name of the captcha.
| Name | Easy | Medium | Hard |
|---|---|---|---|
| Normal | |||
| SlightlyTwisted | |||
| VeryTwisted |
§Mirrors
- Github (https://github.com/TheAwiteb/salvo-captcha)
- Codeberg (https://codeberg.org/awiteb/salvo-captcha)
§Main Repository
§License
This project is licensed under the MIT license for more details see LICENSE or http://opensource.org/licenses/MIT.
Structs§
- Cacache
Storage cacache-storage - The
cacachestorage. Store the token and answer in the disk. - Captcha
- The captcha middleware
- Captcha
Builder - The
Captchabuilder - Captcha
Form Finder - Find the captcha token and answer from the form
- Captcha
Header Finder - Find the captcha token and answer from the header
- Captcha
Query Finder - Find the captcha token and answer from the url query
- Memory
Storage - Captcha storage implementation using an in-memory HashMap.
- Simple
Generator simple-generator - A simple captcha generator, using the
captchacrate.
Enums§
- Captcha
Difficulty simple-generator - Supported captcha difficulties
- Captcha
Name simple-generator - Supported captcha names
- Captcha
State - The captcha states of the request
- Simple
Generator Error simple-generator - Error type for the
SimpleGenerator
Constants§
- CAPTCHA_
STATE_ KEY - Key used to insert the captcha state into the depot
Traits§
- Captcha
Depot Ext - The captcha extension of the depot. Used to get the captcha info from the depot.
- Captcha
Finder - Trait to find the captcha token and answer from the request.
- Captcha
Generator - Captcha generator, used to generate a new captcha image and answer.
- Captcha
Storage - Trait to store the captcha token and answer. is also clear the expired captcha.