2023-08-12 22:12:49 +04:00
|
|
|
justcaptcha
|
|
|
|
===========
|
2022-06-24 23:09:46 +04:00
|
|
|
|
2023-08-12 22:23:52 +04:00
|
|
|
A simple CAPTCHA implementation.
|
2022-06-24 23:09:46 +04:00
|
|
|
|
2023-08-12 22:23:52 +04:00
|
|
|
An example using built-in "dwelling" implementation.
|
2023-01-08 18:34:35 +04:00
|
|
|
|
|
|
|
Create a new CAPTCHA:
|
|
|
|
|
|
|
|
c := dwcaptcha.NewDwellingCaptcha(expiry)
|
|
|
|
_, id := inmemdb.New(someAdditionalDataUsedInIDGenerationUsuallyIPAddr, c)
|
|
|
|
|
|
|
|
Get an image for a CAPTCHA:
|
|
|
|
|
|
|
|
i := inmemdb.Image(captchaID, captchaStyle)
|
|
|
|
if i == nil {
|
2023-05-06 04:49:57 +04:00
|
|
|
... // do something if there was no image returned
|
2023-01-08 18:34:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
jpeg.Encode(w, *i, &jpeg.Options{Quality: 20})
|
|
|
|
|
|
|
|
Solve a CAPTCHA:
|
|
|
|
|
|
|
|
if ok := inmemdb.Solve(captchaID, answer); !ok {
|
|
|
|
... // not solved
|
|
|
|
}
|
|
|
|
// solved
|
|
|
|
...
|
|
|
|
|
|
|
|
Check is CAPTCHA was solved:
|
|
|
|
|
|
|
|
if ok := inmemdb.IsSolved(captchaID); !ok {
|
|
|
|
... // not solved
|
|
|
|
}
|
|
|
|
// solved
|
|
|
|
...
|