General

A Guide on Using .htaccess to Password Protect Your Magento Store

Hello Magento pals,

Last time we learned How to Display programmatically created custom options in admin order details in Magento 2.

Today, we will learn an interesting topic How to Password Protect Your Magento Store With .htaccess in Magento 2, 

Introduction

Basically, there is a huge growth in increase on password guess attacks on Magento installations. Sometimes while surfing you might have noticed that you came across any website who is asking for username and password for granting permission to access the website. Mainly, this type of website is containing passwords to protect against the spammers and hackers. To overcome this problem I have came with the best solution in this article.

Reasons why do you need htaccess authentication.

  1. Google can’t index your secure website. Development server must be protected with HTTP authentication.
  2. When some developments are going on and you don’t want to let people access the website.
  3. Restricted access to website/pages/customers or private website.

Configure Guide

Step 1: Firstly, with the use FTP or Cpanel to reach to Magento 2 root folder.

Step 2: Then open the .htaccess file and add following code at top.

AuthName "User: admin. Password: admin123"

AuthUserFile /patch/to /.htpasswd

AuthType Basic

require valid-user

ErrorDocument 401 "Authorisation Required"

Step 3: Create a file with name of .htpasswd in Magento 2 root. If you want to upload password file somewhere else, you can but make sure you mention the path accordingly in above code then.

Step 4: Use this tool

https://hostingcanada.org/htpasswd-generator/
To setup username and password as given in the below image.

Step 5: Lastly open file .htpasswd now and copy paste the user and encrypted password for example 

admin:$apr1$74z9mjal$JKvdv4G7GMpIxc/8m.OPh0

Where, admin is the username and $apr1$74z9mjal$JKvdv4G7GMpIxc/8m.OPh0 is the password respectively.

Final Words

That’s it for today! By implementing the given above steps you will be able to complete the protection for your website. You can overcome the problem of attacks by spammers and hackers to your website.

Last but not least, if you found the blog interesting, don’t forget to share with your Magento pals. Feel free to Contact Us if you find any difficulty in implementing the above steps.

Happy Magento Learning!

Click to rate this post!
[Total: 4 Average: 5]
Gaurav Jain

Gaurav Jain is Co-Founder and Adobe Certified Expert-Magento Commerce Business Practitioner. Being Computer Engineer?‍? and possessing Extensive Marketing skills he handles all kinds of customer Queries and his Happy? & Helping? Nature makes customer's day Delightful. When he isn’t working, you’ll find Gaurav Reading on Books? or Traveling?. Also, he is Speaker at Magento Meetups.

Recent Posts

How to Add Tooltip in Checkout Shipping Field in Magento 2?

Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…

1 day ago

How to Integrate and Use MongoDB with Laravel?

MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…

2 days ago

NodeJS | Callback Function

In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…

3 days ago

How to Show SKU in Order Summary in Magento 2?

Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…

5 days ago

Best Colors to Use for CTA Buttons

The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…

1 week ago

Magento 2: How to Save Custom Field Value to quote_address for Multi-Shipping Orders

Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…

1 week ago