ic-captcha 0.1.0

Generating CAPTCHAs with given random bytes for the Internet Computer.
Documentation

ic-captcha

License Crates.io Codecov CI Docs.rs Latest Version

ic-captcha is a library that generating CAPTCHAs with given random bytes for the Internet Computer.

It is inspired by captcha-rs.

Usage

See examples and the API documentation for more.

Using mode method

captcha-mode-0.jpeg captcha-mode-0.jpeg captcha-mode-0.jpeg
CaptchaBuilder::new().mode(0) CaptchaBuilder::new().mode(1) CaptchaBuilder::new().mode(2)

Using complexity method

captcha-complexity-1.jpeg captcha-complexity-5.jpeg captcha-complexity-10.jpeg
CaptchaBuilder::new().complexity(1) CaptchaBuilder::new().complexity(5) CaptchaBuilder::new().complexity(10)

Using compression

captcha-compression-10.jpeg captcha-compression-40.jpeg captcha-compression-80.jpeg
captcha.to_base64(10) captcha.to_base64(40) captcha.to_base64(80)

Example

Add the following dependency to the Cargo.toml file:

[dependencies]
ic-captcha = "0.2"

And then get started in your main.rs:

use ic_captcha::CaptchaBuilder;

fn main() {
    {
        let builder = CaptchaBuilder::new();

        let captcha = builder.generate(b"random seed 0", None);
        println!("text: {}", captcha.text());
        println!("base_img: {}", captcha.to_base64(0));

        let captcha = builder.generate(b"random seed 1", None);
        println!("text: {}", captcha.text());
        println!("base_img: {}", captcha.to_base64(0));
    }

    {
        // same as default
        let builder = CaptchaBuilder::new()
            .length(4)
            .width(140)
            .height(60)
            .mode(1)
            .complexity(4);

        let captcha = builder.generate(b"random seed 0", None);
        println!("text: {}", captcha.text());
        println!("base_img: {}", captcha.to_base64(30));
    }
}

License

Copyright © 2024-present LDC Labs.

ldclabs/ic-captcha is licensed under either of Apache License, Version 2.0.