Home » Blogs » Magento Cron: Captcha Delete Expired Images

Magento Cron: Captcha Delete Expired Images

1. Overview

Magento allows captcha in Admin and Customer Login for security purposes. Whenever the administrator or user enters captcha, the captcha image gets stored in the media/captcha/admin folder. Every time when the admin or user does log-in, then the captcha image gets generate and stored that occupies unnecessary space. You can use the cron job function in your coding section to delete all captcha images in Magento. The cron job is the default functionality to delete captcha images.
The cron job will also remove expired captcha images every 10 minutes. Captcha images already get store in a folder. The deleteExpiredImages() function is relate to a cron job. In this blog, you will learn about
  • How to delete expired captcha images,
  • How to Configure Captcha for Admin and Customer,
  • What is Captcha, the example of XML of cron job (config.xml)
  • Info about Admin Captcha, what is Customer Captcha.

2. What is Captcha?

Captcha stands for Completely Automated Public Turing test to tell Computers and Humans Apart. Captcha is a visual device that makes sure the human being is interacting with the website, not a computer.
Magento supports the standard Captcha. It can be used for both Admin and customer account logins. Clicking on the Reload icon in the upper-right corner of the image you can reload the Captcha as many times as required.
You can set the captcha appearance every time, or only after a number of fail login attempts because captcha is fully configurable.

3. How can you delete Expired Captcha Images?

To delete the expired captcha images use the following condition:
$file->getMTime() = Get last modification time of current directory Iterator item.
If the condition is true, then Captcha Image is getting remove from the directory. From this, you can make out that cron job will execute in every 10 minutes. This can be editable in the file of Captcha configuration.
deleteExpiredImages() function is related to a cron job, and it defines in config.xml file with schedule time.
$expire = It is Calculate expire time.
$file->getMTime() = Get last modification time of current directory Iterator item.
if ($file->getMTime() < $expire) { unlink($file->getPathname());
    //unlink function removes image
 }
If the condition is true, then Captcha Image is unlinked(remove) from the directory.

4. The XML of cron job (config.xml)

From this, we can make out that the cron job will get execute in every 10 minutes.
Use this condition in the function of corn job:
if ($file->isFile() &&
     pathinfo($file->getFilename(),
     PATHINFO_EXTENSION)=='png')
     {
       if ($file->getMTime() < $expire) { //Remove expired Image unlink($file->getPathname());
       }
     }
   return $this;
  • Configuration details used:
     
     7
     

5. Know about Admin Captcha

The Shopify store provides free themes that are developed by the Shopify team, and some third-parties designed paid themes.
You can add a Captcha to the Admin Sign In and Forgot Password page for extra security. Clicking on the Reload icon Magento Admin users can reload the Captcha displayed at many times. There is no limit for the number of reloads of Captcha.
Here is the image of Admin sign in with Captcha as follows:

6. What is Customer Captcha

When customers log in to their accounts, or after several unsuccessful attempts to log in then customers need to enter a Captcha each time.
Here is the image of Customer sign in with Captcha as follows:

7. Configure Captcha

You can configure the captcha for admin as well as for your customers.

For the Admin

On the Admin section menubar, go to Stores > Settings > Configuration.
In the left panel, expand the Advance section and choose Admin.
From the upper-right hand side corner, set Store View to Default.
If the scope of your Magento installation includes multiple websites, choose the website(s) where you want the apply the Captcha configuration.
Expand the Captcha section.
Set Enable Captcha in Admin to Yes. Then as per your requirement, you can set all configuration fields and save it.

Configure Captcha for the storefront

On the Admin sidebar, go to Stores > Settings > Configuration.
In the left panel, expand the Advance section and choose Admin.
In the left panel, expand Customers and choose Customer Configuration.
Enable Captcha on Storefront to Yes. Hence, you can configure all fields as per your requirements and then save the configuration.

8. Conclusion

Captcha stands for Completely Automated Public Turing test to tell Computers and Humans Apart. Captcha is a device that ensures the human being is interacting with the website. This blog covers the information on which method should use to delete the captcha images and also about the admin, customer captcha configuration.
Hope, in this blog you will find the answers of how to delete the captcha images and you are now able to delete the captcha images. If you are facing any problem or have a question you can contact us.

Leave A Comment