Thursday, 29 November 2012

How To Secure Your Admin Panel Using .htaccess and .htpasswd


Hello guys,
Today I'm going to show you how to protect your admin panel with a username and password, and make it only accessible for admin IP addresses only!
And, if you have a login page outside of the admin panel, we will look it as well!
To start this, we first need the code bellow to secure the panel:


AuthUserFile /home/admin/.htpasswd
AuthName EnterPassword
AuthType Basic

require valid-user


order deny,allow
deny from all
allow from 111.222.333.444


Now change that code to suit your website, first change the path /home/admin/.htpasswd to the path that you have.
and change the IP address 111.222.333.444 to your IP address!

after editing the code, paste it into .htaccess file inside the admin directory, or just upload it!

Now we need the code bellow:

Security:Geeks
admin:password

You can add as many as you want in the same way.
after you're done, paste that code in the .htpasswd that you mentioned in the .htaccess code /home/admin/.htpasswd
Paste it there, or just upload it!

Finally, for those who doesn't have an "Admin directory" you can lock you admin page/login and make it only accessible for your IP address only!
To lock it, you need the code bellow:
<Files login.php>
Order Deny,Allow
Deny from all
Allow from 111.222.333.444
</Files>

in the code above, the login page is called "login.php" change the name to whatever your admin login page is called.

Now change the 111.222.333.444 to your IP address, then paste the code to the same directory of your login page. or upload it.

That's it guys, hope this was helpful for you.