A small and simple Proof-of-Concept of Captcha (graphical and mathematical) for use in a form generic or in contacts form.
-
Install Composer
-
Run the following command at the root level of your project:
composer install
-
Include gmCaptcha.js (or gmCaptcha.min.js) file from "public/assets/js" directory
<script src="./public/assets/js/gmCaptcha.js" type="text/javascript"></script>
-
Make new instance
<script type="text/javascript"> new gmCaptcha() </script>
-
Call the type of desiderated Captcha:
-
Font customization for graphical Captchas by setting the value of the
appFont
key within the config file; -
Specify the type of operation to be used in mathematical Captchas:
1
for Sum;2
for Subtraction;3
for Multiplication;4
for Division;5
for Random
-
Choose whether or not to use a text file as a dictionary and preload its contents by setting the value of the
appUseDictionary
andappDictionaryFile
keys whithin the config file; -
Specify the minimum and maximum length of words to be taken from the dictionary:
['appDictionarySettings']['minWordLength']
['appDictionarySettings']['maxWordLength']
-
If you choose not to use the Dictionary, the script will generate Captcha with random text.
-
The result of mathematical operations and the text of graphical Captchas are contained in a session variable; its name can be customized by enhancing the contents of the
appSessionVariable
key whithin the config file. -
TextToSpeech (It is only present in the graphical version of the Captcha and you can customize the language via the following parameter):
<script type="text/javascript"> new gmCaptcha({spellLang: "en-US"}) </script>
-
Refresh captchas (It is only present in the graphical version of the Captcha);
-
Error logger.
-
Generate a captcha with random text, directly client-side and display it via HTML's Canvas element.
Note
There are several types of Captcha online, some famous, some less so, all certainly strong and functional.
Why then write "perhaps" useless code?
To "find out how it works," to learn new things, to improve, to feed on knowledge.
Any suggestion, comment or advice, is welcome.