gocaptcha

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2023 License: LGPL-3.0 Imports: 15 Imported by: 0

README

gocaptcha

package main

import (
  "fmt"
  "log"
  "gitler.moe/suwako/gocaptcha"
)

func main () {
  captcha, err := gocaptcha.GenerateCaptcha("font.ttf", gocaptcha.Hiragana, 5)
  if err != nil {
    log.Fatalf("キャプチャを創作に失敗しました。 %v", err)
  }

  input := "あいうえお" // フォームから

  isValid := gocaptcha.VerifyCaptcha(input, captcha.Text)
  if isValid {
    fmt.Println("正解")
  } else {
    fmt.Println("不正")
  }
}

GenerateCaptcha

フォントは自分で受け取って下さい。
おすすめのやつは「Noto Sans」です。

文字モードは:

  • gocaptcha.Latin
  • gocaptcha.Cyrillic
  • gocaptcha.Hiragana
  • gocaptcha.Katakana
  • gocaptcha.Kanji

Documentation

Index

Constants

View Source
const (
	Latin    = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	Cyrillic = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
	Hiragana = "" /* 219-byte string literal not displayed */
	Katakana = "" /* 219-byte string literal not displayed */
	Kanji    = "" /* 1368-byte string literal not displayed */
)

Variables

This section is empty.

Functions

func VerifyCaptcha

func VerifyCaptcha(input, captchaText string) bool

Types

type Captcha

type Captcha struct {
	Text  string
	Image []byte
}

func GenerateCaptcha

func GenerateCaptcha(fontPath, charset string, length int) (*Captcha, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL