This article will show you how to password protect your EECS webpages using Apache Htpasswd.
 
Step 1. Create a .htpasswd file
First, you need to create a .htpasswd file to contain the usernames and encrypted passwords of users on your website. This folder should be placed in the public_html directory on the EECS servers. Each password must be encrypted using a tool like Htpasswd Generator. Inputting a username and password into the website should return a string that looks like this:
foo:$apr1$HT.tJ9dt$BZrCs2JfjkoyRnJyQTjeu0
These generated strings should be placed in the .htpasswd file. Multiple usernames and passwords can be stored in the .htpasswd file, each separated by a newline.
 
Step 2. Protecting a directory
To protect a directory, first create the directory that you wish to protect in public_html. Once you've done this, a file named .htaccess should be placed inside the directory that contains the following text:
AuthUserFile /path/to/.htpasswd
AuthType Basic
AuthName "Protected Directory"
Require valid-user
where /path/to/.htpasswd is the full path to the .htpasswd file on the server. Once you've created this file, your directory should be password protected.
 
Step 3. Password protecting a file
If you wish to only protect a single file, place the .htaccess file in the same directory and insert the following text:
AuthUserFile /path/to/.htpasswd
AuthType Basic
AuthName "Protected File"

<Files "page.html">
    Require valid-user
</Files>
where page.html is the name of the page that you want to password protect.
 
Step 4. Accessing your protected pages
When you attempt to access your protected page, you should be met with a prompt like this:
After entering a valid username and password, you should have access to the protected page.
 
 

Add Feedback