Current location: Hot Scripts Forums » Programming Languages » PHP » Best way to protect directory?


Best way to protect directory?

Reply
  #1 (permalink)  
Old 07-20-04, 05:40 PM
kvnband kvnband is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 242
Thanks: 0
Thanked 0 Times in 0 Posts
Best way to protect directory?

Hi, I'm looking for the following (It is just for teaching myself, so any comments are welcome)

Let's say I have a database of users and md5 passwords (mysql)

What is the best way to provide a SECURE login for this? I don't want to use sessions for this, as the pages under the SECURE directory are just plain HTML files or say file downloads. I'm thinking that using the .htaccess method is best...well, OK, I want to know: Is it possible to somehow....just like .htaccess protect the directory, but let it be dynamic? So that every time directory is requested, the usual Browser username/password box pops up, but instead of a flat file, it pulls info from database?

Or, even a script that will pull info from database, and store in the .htpasswd file?

Thanks for reading,
Kevin
Reply With Quote
  #2 (permalink)  
Old 07-20-04, 05:49 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
put an index.php in every directory that will check permission that are set in a database.

Say you have a table
userid, user, pass

and another table
userid,directory

then you could just check the userid and pass it via the querystring or post.

You can get around sessions by using the database and passing a hash like vbulletin does, this is sometimes a better method because the sessionhash is like a combination of ip and user agent which kind of blocks it down.
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Reply With Quote
  #3 (permalink)  
Old 07-20-04, 06:08 PM
kvnband kvnband is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 242
Thanks: 0
Thanked 0 Times in 0 Posts
Well, this is just a general member's area that I'm talking about here. Everyone gets access to the directory, as long as they are verified. Now, about placing an index.php to check if they are verified. I don't quite understand this, because what if they accessed

/memberarea/page27.html or something like that? I know that you know your stuff, that's why I'm asking these questions.

Thanks,
Kevin
Reply With Quote
  #4 (permalink)  
Old 07-20-04, 07:10 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
Oh okay I was thinking you wanted something different.

I did a cursory look on apache.org regarding it's use of the .htpasswd/.htaccess and it doesn't appear you can have the server look in the database.

However you can make a script to write these files on adding of user to your database. Just do a fopen() ect...
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Reply With Quote
  #5 (permalink)  
Old 07-20-04, 07:19 PM
kvnband kvnband is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 242
Thanks: 0
Thanked 0 Times in 0 Posts
Ah, but the question is: Database of users and md5 passwords already exists. Now, I need to write to a file called .htpasswd with user:UNIX style password

I was thinking this is the way I'd have to do it, but how do I convert from md5 to UNIX?

Actually, thinking as how md5 is not reversible, I guess that this probably isn't possible. So let's say that the passwords are in plain text. How would I convert from plain text to unix style passwords. (Yes, I've looked, can't find anything)

Please keep in mind that this is just a 'what if' scenario, and I'm open to anything.

Kevin
Reply With Quote
  #6 (permalink)  
Old 07-20-04, 08:22 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
Basically there is a few different encrpytiong methods and you would have to check with the httpd conf on apache to figure out how to do it in a pure php manner but to do is using exec you can use htpasswd

Usage:
htpasswd [-cmdps] passwordfile username
htpasswd -b[cmdps] passwordfile username password

htpasswd -n[mdps] username
htpasswd -nb[mdps] username password
-c Create a new file.
-n Don't update file; display results on stdout.
-m Force MD5 encryption of the password.
-d Force CRYPT encryption of the password (default).
-p Do not encrypt the password (plaintext).
-s Force SHA encryption of the password.
-b Use the password from the command line rather than prompting for it.

This will let you do what you want I believe.
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Protecting only one file in a directory from hotlinking demomen Script Requests 1 10-17-04 07:58 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM
international directory post your url for free gemsergio Traffic Exchange 0 01-08-04 06:04 PM
? on users accessing a directory mdhall PHP 10 10-18-03 12:25 PM
Showing images in a directory Bob PHP 4 08-25-03 08:16 AM


All times are GMT -5. The time now is 04:13 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.