Solved

Understanding htaccess (htpasswd)

Posted on 2010-09-07
7
501 Views
Last Modified: 2012-05-10
I've inherited a website template from another programmer. The task was simple enough, copy the entire website, change the content (including database links). He is using the .htaccess file, a file I am not familiar with.

I'm currently working on the admin section of this site.
There a note in the code, on the line for the username and password for the admin section, that says "// change this value when password changes for admin along with htpasswd file". I've done a site search and can't find a file named htpasswd.
If I change the password in the admin file, the website can never authenticate the password and I can't login.

There is the .htaccess file. The code for that is below. If I change "oldsite" to "newsite" the page, after login, will display a 500 Internal Server Error.

I've never used the .htaccess file before, and I'm not really sure where to start.
Everything else on the site is ready to go, except for changing the password to the current site. If I use the old password, everything works just fine.


AuthName "Restricted Area" 

AuthUserFile "/home/oldsite/etc/passwd"

AuthType Basic

require valid-user

Open in new window

0
Comment
Question by:kentcommunications
  • 3
  • 2
  • 2
7 Comments
 
LVL 15

Expert Comment

by:Insoftservice
Comment Utility
HI,
may i get the complete  htaccess rule
0
 

Author Comment

by:kentcommunications
Comment Utility
The code I attached is the entire contents of the .htaccess file.
0
 
LVL 15

Expert Comment

by:Insoftservice
Comment Utility
hi,

chk the path of the htpasswd file

AddType text/x-component .htc
RewriteEngine on
AuthType Basic
AuthName "Restricted Area"
AuthUserFile "/home/oldsite/etc/passwd"
require valid-user
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Accepted Solution

by:
chrisbloom7 earned 500 total points
Comment Utility
AuthUserFile "/home/oldsite/etc/passwd"

That line contains the path to the password file. You can either grab it from the old server, or create a new one and update the path to the new file. If you have to create a new one, note the next line in the htaccess file:

require valid-user

That line probably describes a group of users rather than a single user. You can find out more about the process of creating passwords and groups at http://httpd.apache.org/docs/2.2/howto/auth.html
0
 
LVL 4

Expert Comment

by:chrisbloom7
Comment Utility
Sorry - I need to correct that last part. valid-user is actually a keyword, not a user nor a group. If it were a group there would be an extra AuthGroupFile directive and the group name would be preceded with the word "group", as in

require group valid-user

Instead the keyword valid-user means allow anyone in that is using a valid username and password, as defined in the password file. Again, refer to the documentation I linked to.
0
 
LVL 4

Expert Comment

by:chrisbloom7
Comment Utility
Also, I feel compelled to say that Basic Authentication is not the best way to protect an administration area as it requires external functionality to protect the pages. In other words, if Apache isn't configured properly the pages are unprotected but still accessible. Better to use the scripting language itself (PHP) to restrict access to the files. You will have much more control and flexibility and no external requirements.
0
 

Author Comment

by:kentcommunications
Comment Utility
I copied the passwd file from the original site to the new one. It only contains one line, an encrypted password.

As you said, this isn't the best way to do user authentication (I've never worked with this method) so I'm just going to set it up through PHP, I'm thinking its less of a hassle at this point.

Thanks!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now