arnaucube
arnaucube/goCaptchaPublic Self-hosted repository
goCaptcha/README.md
README.mdRaw
  1# goCaptcha
  2captcha server, with own datasets, to train own machine learning AI
  3
  4
  5### How to use?
  6
  71. Get the captcha:
  8```
  9GET/ 127.0.0.1:3025/captcha
 10```
 11Server response:
 12```json
 13{
 14    "id": "881c6083-0643-4d1c-9987-f8cc5bb9d5b1",
 15    "imgs": [
 16        "7cf6f630-e78f-469c-85dd-2d677996fea1.png",
 17        "d4014318-f875-4b42-b704-4f5bf5e5e00c.png",
 18        "2dd69b44-903d-4e78-bb7b-f8b07877c9e5.png",
 19        "2954fc38-819d-40c9-ae3e-7b6fbb68ddbe.png",
 20        "b060f58a-d44b-4e05-b466-92aa801a2aa1.png",
 21        "1b838c46-b784-471e-b143-48be058c39a7.png"
 22    ],
 23    "question": "leopard",
 24    "date": ""
 25}
 26```
 27
 282. User selects the images that fit in the 'question' parameter
 29(in this case, 'leopard')
 30
 313. Post the answer. The answer contains the CaptchaId, and an array with the selected images
 32```
 33POST/ 127.0.0.1:3025/answer
 34```
 35Post example:
 36```json
 37{
 38	"captchaid": "881c6083-0643-4d1c-9987-f8cc5bb9d5b1",
 39	"selection": [0,0,0,0,1,1]
 40}
 41```
 42Server response:
 43```
 44true
 45```
 46
 47### How this works?
 48
 49###### Server reads dataset
 50First, server reads all dataset. Dataset is a directory with subdirectories, where each subdirectory contains images of one element.
 51
 52For example:
 53```
 54imgs/
 55    leopard/
 56        img01.png
 57        img02.png
 58        img03.png
 59        ...
 60    laptop/
 61        img01.png
 62        img02.png
 63        ...
 64    house/
 65        img01.png
 66        img02.png
 67        ...
 68```
 69Then, stores all the filenames corresponding to each subdirectory. So, we have each image and to which element category is (the name of subdirectory).
 70
 71
 72###### Server generates captcha
 73When server recieves a GET /captcha, generates a captcha, getting random images from the dataset.
 74
 75For each captcha generated, generates two mongodb models:
 76```json
 77Captcha Model
 78{
 79    "id" : "881c6083-0643-4d1c-9987-f8cc5bb9d5b1",
 80    "imgs" : [
 81        "7cf6f630-e78f-469c-85dd-2d677996fea1.png",
 82        "d4014318-f875-4b42-b704-4f5bf5e5e00c.png",
 83        "2dd69b44-903d-4e78-bb7b-f8b07877c9e5.png",
 84        "2954fc38-819d-40c9-ae3e-7b6fbb68ddbe.png",
 85        "b060f58a-d44b-4e05-b466-92aa801a2aa1.png",
 86        "1b838c46-b784-471e-b143-48be058c39a7.png"
 87    ],
 88    "question" : "leopard"
 89}
 90```
 91
 92```json
 93CaptchaSolution Model
 94{
 95    "id" : "881c6083-0643-4d1c-9987-f8cc5bb9d5b1",
 96    "imgs" : [
 97        "image_0022.jpg",
 98        "image_0006.jpg",
 99        "image_0050.jpg",
100        "image_0028.jpg",
101        "image_0119.jpg",
102        "image_0092.jpg"
103    ],
104    "imgssolution" : [
105        "camera",
106        "camera",
107        "laptop",
108        "crocodile",
109        "leopard",
110        "leopard"
111    ],
112    "question" : "leopard"
113}
114```
115Both models are stored in the MongoDB.
116
117Captcha Model contains the captcha that server returns to the petition. And CaptchaSolution contains the solution of the captcha. Both have the same Id.
118
119
120###### Server validates captcha
121When server recieves POST /answer, gets the answer, search for the CaptchaSolution based on the CaptchaId in the MongoDB, and then compares the answer 'selection' parameter with the CaptchaSolution.
122
123If the selection is correct, returns 'true', if the selection is not correct, returns 'false'.