GithubHelp home page GithubHelp logo

ic-captcha's Introduction

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.

captcha logo

Usage

See examples and the API documentation for more.

Using mode method

CaptchaBuilder::mode Captcha Preview
mode(0): dark on light captcha-mode-0
mode(1): colorful on light captcha-mode-0
mode(2): colorful on dark captcha-mode-0

Using complexity method

CaptchaBuilder::complexity Captcha Preview
complexity(1) captcha-complexity-1
complexity(5) captcha-complexity-5
complexity(10) captcha-complexity-10

Using compression

Captcha::to_base64 Captcha Preview
to_base64(10): 1.49KB captcha-compression-10.jpeg
to_base64(40): 2.68KB captcha-compression-40.jpeg
to_base64(80): 5.21KB captcha-compression-80.jpeg

Example

Add the following dependency to the Cargo.toml file:

[dependencies]
ic-captcha = "1.0"

And then get started in 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.

ic-captcha's People

Contributors

zensh avatar

Stargazers

伊欧 avatar Dee Cheung avatar Ethan Celletti avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.