Added a library usage example in README.
This commit is contained in:
parent
073384cc34
commit
ee93284cdc
36
README.md
36
README.md
@ -95,4 +95,38 @@ And if answer was correct a client gets a HTTP code 202. Or 403 otherwise.
|
|||||||
|
|
||||||
Then a server checks if CAPTCHA was solved with following request.
|
Then a server checks if CAPTCHA was solved with following request.
|
||||||
|
|
||||||
GET /n60f2K9JiD5c4qX9MYe90A54nT0nnJrtgfhAjfaWtBg
|
GET /n60f2K9JiD5c4qX9MYe90A54nT0nnJrtgfhAjfaWtBg
|
||||||
|
|
||||||
|
## Library usage
|
||||||
|
|
||||||
|
A simple example using built-in dwelling CAPTCHA implementation.
|
||||||
|
|
||||||
|
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 {
|
||||||
|
... // error handling
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
...
|
Loading…
Reference in New Issue
Block a user