Page 1 of 1

captcha font

Posted: Tue Jun 26, 2018 2:02 am
by aerogel
hi
is there a way to change the generated captha font?
tnx

Re: captcha font

Posted: Tue Jun 26, 2018 9:35 am
by rjcalifornia
sedra wrote:
Tue Jun 26, 2018 2:02 am
hi
is there a way to change the generated captha font?
tnx
Depends of the plugin. If you are using Google captcha, you might want to start here:

https://developers.google.com/recaptcha ... tomization

Re: captcha font

Posted: Tue Jun 26, 2018 5:01 pm
by paulfeakins
sedra wrote:
Tue Jun 26, 2018 2:02 am
is there a way to change the generated captha font?
Why?

Re: captcha font

Posted: Thu Jun 28, 2018 2:08 am
by aerogel
im using the built in basic captcha and honestly it is hard to read and i prefer more stylish font.

Re: captcha font

Posted: Thu Jun 28, 2018 2:11 am
by straightlight
In this case, it would rather be suggested to look for extensions on the Marketplace that already provides better presentations for Captcha to save you the trouble. Otherwise, you'd still need to modify each CSS files according to each themes you might be currently using.

Re: captcha font

Posted: Thu Jun 28, 2018 2:14 am
by aerogel
i guess a php function generates the captcha image. maybe there is an option for changing the default font for the function? i dont like to add other extensions or modules or addons whatsoever to keep things more simple and easy to manage and easy to restore.

Re: captcha font

Posted: Thu Jun 28, 2018 2:28 am
by straightlight
sedra wrote:
Thu Jun 28, 2018 2:14 am
i guess a php function generates the captcha image. maybe there is an option for changing the default font for the function? i dont like to add other extensions or modules or addons whatsoever to keep things more simple and easy to manage and easy to restore.
The Basic Captcha uses GD Library to form the algorithm from catalog/controller/extension/captcha/basic.php file. This is where you'd need to make the modifications to suit your needs.

Re: captcha font

Posted: Fri Jun 29, 2018 5:43 am
by aerogel
after 8 hours of digging internet and tinkering, this is how you can change basic captcha font:
download a free and good looking true type font and rename it to a random complex name for being nearly impossible to guess.
put the font in image folder.
go to the catalog/controller/extension/captcha and open basic.php for editing.
comment out this line:

Code: Select all

imagestring($image, 10, intval(($width - (strlen($this->session->data['captcha']) * 9)) / 2), intval(($height - 15) / 2), $this->session->data['captcha'], $black);
at line number 48 and add this one:

Code: Select all

$font = './image/YourComplexFontName.ttf';
//you can use this as a guide
imagettftext($finalimage,fontsize,angle,lowerleftX,lowerleftY,fontcolor,fontpath,captchatext);
imagettftext($image, 20, 0, intval(($width - (strlen($this->session->data['captcha']) * 9)) / 2) - 20, 35 - intval(($height - 15) / 2), $black, $font , $this->session->data['captcha']);
you can fine tune the position of the captcha according to your font using lowerleftX and lowerleftY variables (as i have done above).
i also recommend to change the image type to PNG for clearer result. it means you need to change header type in next lines to:

Code: Select all

header('Content-type: image/png');
imagepng($image);
done!
repeat the above procedure for the admin captcha through this address admin/controller/common/base.php.
now the captcha is more secure and looks more professional!(i guess :D)

How to change which symbols to show in image AND ENTER IN FORM ???

Posted: Mon Jul 29, 2019 2:37 pm
by karadev
Hello friend, I did this example and it works great :) I recommend you insert into the default install base in opencart for all versions. I use the font ARIAL.ttf is great for users and you can see normal text in captcha.

I have a question about you. how can i control characters that show in captcha and i need to write so that users can pass CAPTCHA !!!

Example use for me is someone like this to tell the script what symbols to use:
symbols_using_captcha = a-z, A-Z, 0-9;
i do not know how to encode it but i see it can do it :)
and the second question is about this line in your code:
// imagettftext ($ finalimage, FONTSIZE, angle, lowerleftX, lowerleftY, FONTCOLOR, FontPath, captchatext)
how to use these settings? and can you give an example of one or two or all settings :)

Thanks in further and best regards for you and poeple like you in this system :)

Re: captcha font

Posted: Mon Jul 29, 2019 2:54 pm
by letxobnav
now the captcha is more secure and looks more professional!(i guess :D)
More secure, no, more professional, hardly.
I recommend you insert into the default install base in opencart for all versions. I use the font ARIAL.ttf is great for users and you can see normal text in captcha.
I don't as the basic concept of a captcha is that it is supposed to be difficult to read, that is the whole point.

Re: captcha font

Posted: Mon Jul 29, 2019 3:13 pm
by karadev
dude, i know what is the whole point. i am asking you for explane settings of comment line and give some example for that. in before lines in my message i just want to explane to you what i make with your example. that is all

give some example for this line here //imagettftext($finalimage,fontsize,angle,lowerleftX,lowerleftY,fontcolor,fontpath,captchatext)
all point i know what is

Re: captcha font

Posted: Mon Jul 29, 2019 4:16 pm
by letxobnav
you lost me at "dude".

Re: captcha font

Posted: Mon Jul 29, 2019 4:20 pm
by paulfeakins