Solved

Understanding htaccess (htpasswd)

Posted on 2010-09-07
7
503 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
ID: 33619903
HI,
may i get the complete  htaccess rule
0
 

Author Comment

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

Expert Comment

by:Insoftservice
ID: 33624192
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 4

Accepted Solution

by:
chrisbloom7 earned 500 total points
ID: 33626465
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
ID: 33626513
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
ID: 33626533
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
ID: 33627437
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

912 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

20 Experts available now in Live!

Get 1:1 Help Now