0.2.0 • Published 2 years ago

use-offline-captcha v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

use-offline-captcha

This is React captcha hook for offline application.

This hook does not communicate with the server. Only generate and validate code through only Client. If security is critical, DO NOT USE THIS LIBRARY.

NPM JavaScript Style Guide

Install

npm install --save use-offline-captcha

Preview

Demo

Usage

import { useEffect, useState, useRef } from 'react'
import useCaptcha from 'use-offline-captcha'

export default function App() {
    const captchaRef = useRef()
    const [value, setValue] = useState()
    const userOpt = {
        type: 'mixed', // "mixed"(default) | "numeric" | "alpha" 
        length: 5, // 4 to 8 number. default is 5
        sensitive: false, // Case sensitivity. default is false
        width: 200, // Canvas width. default is 200
        height: 50, // Canvas height. default is 50
        fontColor: '#000',
        background: 'rgba(255, 255, 255, .2)'
    }
    const { gen, validate } = useCaptcha(captchaRef, userOpt)

    useEffect(() => {
      if (gen) gen()
    }, [gen])

    const handleValidate = () => {
        const isValid = validate(value)
    }

    const handleRefresh = () => gen()

    return (
        <>
            <div ref={captchaRef} />
            <input onChange={(e) => setValue(e.target.value)} value={value} />
            <button onClick={handleValidate}>Validate</button>
            <button onClick={handleRefresh}>Refresh</button>
        </>
  );
}

Options

KeyDescriptionValue
*type'numeric' only comes with numbers and 'alpha' only with alphabets. 'mixed' comes in a mixed form, but it cannot be guaranteed that only mixed forms come out. default is 'mixed''mixed', 'numeric', 'alpha'
lengthSet maximum length of captcha. default is 54 - 8
sensitiveSet case sensitivity. default is falsetrue or false
widthSet captcha canvas width. default is 200
heightSet captcha canvas height. default is 50
fontColorSet captcha canvas font color. default is #000
backgroundSet captcha canvas background color. default is rgba(255, 255, 255, .2)

License

MIT © tofutree23


This hook is created using create-react-hook.

0.2.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.0

2 years ago