FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.
Knowledgebase: Password Protection
Password protect single files?
Posted on 26 January 2004 09:27 AM
Question:

Can I easily password protect a single file or page? In using the File Manager it appears that I can only password protect directories?

Answer:

You can follow the instructions described in "How do I password protect part of my web site?", however you will need to make manual modifications to restrict it to protect only one file.

The easiest way, especially for those not comfortable with the command line (ie "manual method"), is to first use the CNC to password protect the directory that the file is in. See "Password Protection: Automagically".

After you have done so, there will be an .htaccess file within the directory. That .htaccess file will need to be modified to tell it to only require a username/password when accessing a particular file and not all of the files within the directory. To use the CNC File Manager to do so, select the .htaccess file by clicking the box in front of the filename and then click the Edit File button.

When viewing the contents of the .htaccess file, you should see something like the following:

### CNC_START: BEGIN CNC PASSWORD PROTECTION
### DO NOT EDIT THIS SECTION, CHANGES WILL BE LOST!
AuthUserFile /big/dom/xdomain/.sys_opr_dir/CNC_Protect/.passwd
AuthName Protected_Area
AuthType Basic
require user username
### CNC_END: END CNC PASSWORD PROTECTION

(Note: xdomain will reflect your xdomain and username will be the username you specified for the password protection.)

You'll need to replace the require user username line shown in bold above with the following:

<Files "mypage.html">
require user username
</Files>


(Make sure you replace mypage.html with the name of the file you want protected and username with the username you specified for the password protection. Also, you can go ahead and remove all lines that begin with ###.)

What you should end up with is the following:

AuthUserFile /big/dom/xdomain/.sys_opr_dir/CNC_Protect/.passwd
AuthName Protected_Area
AuthType Basic
<Files "mypage.html">
require user username
</Files>


If you wish, you can also change the prompt of Protected_Area to something else, such as Restricted_Area, Login_Required, etc. Note, however, that it can only be a few characters and you should also avoid using spaces with the AuthName to prevent strange behavior with certain browsers.

An enhanced version of the Password Protection section of the CNC is expected to be included with a future release.