Showing posts with label Joomla. Show all posts
Showing posts with label Joomla. Show all posts

How to make own captcha in Joomla?

The captcha can be used in many places to validate whether the user is real or not. It helps in maintaining the security of the site.
The following function will make an image that contains a random captcha in Joomla.

<?php
        public function makeCaptcha()
        {
            $string = JUserHelper::genRandomPassword ('6');
            $session = JFactory::getSession();
            $session->set('value', $string);
            $width      = 100;
            $height     = 25;
            $image      = imagecreatetruecolor ($width , $height);
            $text_color = imagecolorallocate($image, 130, 130, 130);
            $bg_color   = imagecolorallocate($image, 190, 190, 190);
            imagefilledrectangle($image, 0, 0, $width, $height, $bg_color);
            imagestring($image, 5, 16, 4, $string, $text_color);
            ob_start();
            imagejpeg ($image);
            $jpg = ob_get_clean ();
            return "data:image/jpeg;base64," . base64_encode($jpg);
        }
?>