You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
3.2 KiB

7 years ago
<img src="" alt="Captcheck" style="max-width: 50%;" />
7 years ago
7 years ago
6 years ago
Easy, light, self-hostable CAPTCHA service. Works on modern browsers (and
IE9+). Uses a selection of icons from Font-Awesome. Text-only accessibility
7 years ago
mode and support for keyboard-only operation.
7 years ago
7 years ago
Thanks to for supplying the data for the text CAPTCHA.
7 years ago
How to use
6 years ago
In your form, put an empty div with the class "captcheck_container".
Add `captcheck.js` (or `captcheck.min.js`) into your page.
7 years ago
<!DOCTYPE html>
<title>Captcheck Sample Form</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="captcheck.js"></script>
<form action="submit.php">
<input type="text" name="form_field" placeholder="Some random form field" />
<div class="captcheck_container">
7 years ago
<button type="submit">Submit Form</button>
6 years ago
When the form is submitted, your server will receive two extra form fields:
7 years ago
`captcheck_session_code` and `captcheck_selected_answer`.
6 years ago
In your form handling code, send a request to `http(s)://captcheck-url/api.php`.
Pass the variables `session_id` and `answer_id` with the values sent with the form,
and also pass the variable `action` with the value `verify`.
You will receive a JSON response with (among other things) `"result": true` or
`"result": false`. If result is false, the user failed the test, and another
7 years ago
variable `msg` is available with an explanation.
6 years ago
Example URL:
7 years ago
6 years ago
Example responses:
7 years ago
`{"session":"some_session_id","result":false,"msg":"Answer incorrect."}`
### Content-Security-Policy and Nonces
6 years ago
Add `data-stylenonce="nonce_here"` to the `.captcheck_container` div.
If you have multiple CAPTCHAs on one page, only one of them needs the nonce
7 years ago
1. Run composer install.
2. Copy settings.template.php to settings.php and plug in your settings.
3. Install the database.
4. Customize captcheck.js with the correct api_url.
5. Follow the How to Use section and the example setup in test.html and test.php.
7 years ago
Execution Flow
6 years ago
JS = captcheck.js, API = api.php, FORM = parent form,
7 years ago
SITE = form processing code, -> = some action taken on the right by the left
JS -> API: Request session ID, question, and answers (with scrambled random codes)
API -> JS: Sends info, saves session ID, correct answer, and scrambled answer codes in DB
JS -> API: Requests answer images by sending scrambled value and session ID
JS -> FORM: Adds hidden field with value=session ID, displays question and images (or text box)
7 years ago
SITE -> API: Sends session ID and answer
7 years ago
API -> SITE: Responds with true/false to indicate if the answer is valid, marks session as expired to prevent CAPTCHA reuse