473,799 Members | 3,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simplest scheme for password protection?

Hello,

I'm using PHP 4.4.4 with MySQL 5.0. I have a USERS table wher I store
a username and password for each user. I have a directory (containing
both HTML and PHP files) that I would like only logged in users to
access. What is the simplest scheme for password protecting thsi
directory? I would prefer not to touch every page and add access
control logic, but if that's the easiest way, so be it.

Your thoughts are greatly appreciated. - Dave

Oct 23 '06 #1
7 1315
Ron
<la***********@ zipmail.comwrot e in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
Hello,

I'm using PHP 4.4.4 with MySQL 5.0. I have a USERS table wher I store
a username and password for each user. I have a directory (containing
both HTML and PHP files) that I would like only logged in users to
access. What is the simplest scheme for password protecting thsi
directory? I would prefer not to touch every page and add access
control logic, but if that's the easiest way, so be it.

Your thoughts are greatly appreciated. - Dave
Dave,
if your server supports it you could use .htaccess files (apache style) to
control user access.
otherwise you can write a simple access control system and make it a
require_once in each PHP file.

Only the .htaccess will protect the html files on their own, It is often
useful to put pages and fragments that you don't want users to discover in
directories outside of the browsing path of the user, then get PHP to
include or require them as needed.

Cheers

Ron
Oct 23 '06 #2
Following on from la***********@z ipmail.com's message. . .
>Your thoughts are greatly appreciated. - Dave
The _simplest_ scheme may not be the /most suitable/.

Basics:
1 Don't store the password, but a hash of it
2 Check authority to run a page on every page

The simplest scheme operates as you expect with
1 Force a login (see 3)
2 Validate login and set 'OK' flag in $_SESSION
3 Check the 'OK' flag at the top of each page and redirect to login if a
problem

In case you didn't know. You can put restricted content outside the web
root. PHP will be able to access these but browsers won't. Feed that
content into your web pages somehow and you have complete control. To
do this you might use the include directive or fopen() etc.
/webroot/phppages
/webroot/imagebits
/webroot/css
/library/phots
/library/sound
/database/mysql

All the web root directories are visible to browsers none of the others
are


--
PETER FOX Not the same since the submarine business went under
pe******@eminen t.demon.co.uk.n ot.this.bit.no. html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.dem on.co.uk>
Oct 23 '06 #3
I have seen .htaccess files, but how can they be built so that they
read from a database of stored username and passwords?

Thanks, - Dave
Ron wrote:
<la***********@ zipmail.comwrot e in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
Hello,

I'm using PHP 4.4.4 with MySQL 5.0. I have a USERS table wher I store
a username and password for each user. I have a directory (containing
both HTML and PHP files) that I would like only logged in users to
access. What is the simplest scheme for password protecting thsi
directory? I would prefer not to touch every page and add access
control logic, but if that's the easiest way, so be it.

Your thoughts are greatly appreciated. - Dave

Dave,
if your server supports it you could use .htaccess files (apache style) to
control user access.
otherwise you can write a simple access control system and make it a
require_once in each PHP file.

Only the .htaccess will protect the html files on their own, It is often
useful to put pages and fragments that you don't want users to discover in
directories outside of the browsing path of the user, then get PHP to
include or require them as needed.

Cheers

Ron
Oct 23 '06 #4
Rik
la***********@z ipmail.com wrote:
I have seen .htaccess files, but how can they be built so that they
read from a database of stored username and passwords?
That's not that simple.
You could make .htpasswd files on the fly, but that's hardly preferable, as
you'll have to create, maintain and verify the file on every change in
users.

What I'd do:
create a .htaccess file:

RewriteCond %{REQUEST_FILEN AME} -f
RewriteCond %{REQUEST_FILEN AME} !^accesscontrol .php
RewriteRule ^(.*?)$ accesscontrol.p hp?file=$i&%{QU ERY_STRING} [NC,L]

And handle authentication in accesscontrol.p hp, and possibly include the
requested files, or give a Unauthorised header.
--
Grtz,

Rik Wasmus
Oct 23 '06 #5
Thanks, Rik. This is the solution I'll pursue. But I have one follow
up question. What does "accesscontrol. php" return upon successful
authentication and upon authentication failure?

- Dave
Rik wrote:
la***********@z ipmail.com wrote:
I have seen .htaccess files, but how can they be built so that they
read from a database of stored username and passwords?

That's not that simple.
You could make .htpasswd files on the fly, but that's hardly preferable, as
you'll have to create, maintain and verify the file on every change in
users.

What I'd do:
create a .htaccess file:

RewriteCond %{REQUEST_FILEN AME} -f
RewriteCond %{REQUEST_FILEN AME} !^accesscontrol .php
RewriteRule ^(.*?)$ accesscontrol.p hp?file=$i&%{QU ERY_STRING} [NC,L]

And handle authentication in accesscontrol.p hp, and possibly include the
requested files, or give a Unauthorised header.
--
Grtz,

Rik Wasmus
Oct 23 '06 #6
la***********@z ipmail.com wrote:
I have seen .htaccess files, but how can they be built so that they
read from a database of stored username and passwords?

Thanks, - Dave
Ron wrote:
>><la********** *@zipmail.comwr ote in message
news:11****** *************** *@e3g2000cwe.go oglegroups.com. ..
>>>Hello,

I'm using PHP 4.4.4 with MySQL 5.0. I have a USERS table wher I store
a username and password for each user. I have a directory (containing
both HTML and PHP files) that I would like only logged in users to
access. What is the simplest scheme for password protecting thsi
directory? I would prefer not to touch every page and add access
control logic, but if that's the easiest way, so be it.

Your thoughts are greatly appreciated. - Dave

Dave,
if your server supports it you could use .htaccess files (apache style) to
control user access.
otherwise you can write a simple access control system and make it a
require_onc e in each PHP file.

Only the .htaccess will protect the html files on their own, It is often
useful to put pages and fragments that you don't want users to discover in
directories outside of the browsing path of the user, then get PHP to
include or require them as needed.

Cheers

Ron

If you're using a MySQL database, see mod_auth_mysql (available on
sourceforge.net ).
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Oct 24 '06 #7
Rik
la***********@z ipmail.com wrote:
Thanks, Rik. This is the solution I'll pursue. But I have one follow
up question. What does "accesscontrol. php" return upon successful
authentication and upon authentication failure?

$logged_in = your_own_code() ;
if(!$not_logged _in){
header('HTTP/1.0 401 Unauthorized');
exit;
}
$path = parse_url($_GET['file'],PHP_URL_PATH);
$file = dirname(__FILE_ _).'/'.$fake_url['path'];
if(!is_file($fi le){
header("HTTP/1.0 404 Not Found");
exit;
}
$ext = pathinfo($file, PATHINFO_EXTENS ION);
if(strcasecmp($ ext,'php') || strcasecmp($ext ,'html'){
include($file);
exit;
}
$ext_mime = array(
'jpg' ='image/jpeg',
'pdf' ='application/pdf',
etc...);
header('Content-type: '.$ext_mime[$ext]);
readfile($file) ;

--
Rik Wasmus
Oct 24 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3362
by: Lou | last post by:
Please can someone put me out my misery! Im trying to find a multiple user/password protection script that will redirect the specific user to a specific directory. At the moment I have set up htaccess which is fine but can only protect one directory unless I put htaccess on each directory which I think is a bit long winded, but is there any other way I can do this with using only one password script? Any info would be greatly...
7
2150
by: juglesh | last post by:
<body><div align="center"> <?php if (!isset($password)){ ?><form action="<?php $_SERVER; ?>" method="post"> type password here&nbsp;<input name="password" type="text" size="8"> then <input name="submit" type="submit"> </form> <?php die; }
6
25273
by: Geert-Pieter Hof | last post by:
Hello, My VB 6.0 application read and writes data from and to a MS Excel workbook, using the Microsoft.Jet.OLEDB.4.0 provider. Now I want to protect the Excel workbook with a password, but I figured out that it is not possible to open the workbook for data access with ADO (http://support.microsoft.com/?KBID=211378). Is there another way to use a password protected Excel workbook in my
7
1850
by: Borked Pseudo Mailed | last post by:
Seeking feedback on Password Protection via Java/JavaScript ONLY (no cgi): SEE: http://online_tools.home.att.net/tools.html *AND* http://online_tools.home.att.net/extraCode.htm Thanks.
5
2999
by: Brent Burkart | last post by:
I want to protect my website with a user and password. I have SQL Server 2000 where I want to store the users and passwords and the website is complete. I just need to add in some security with password protection. Can anyone help me out?
6
2416
by: Frank L | last post by:
I have some accounting and tax receipting type applications, developed for charitable and non profit groups, that are exhibiting strange behaviour on a few of the 30 or 40 user machines. When some users (about 3 or 4 it seems) close the frontend db the Access database password prompt appears. Users can just Cancel the pw prompt (or enter the correct password) and the db will then close. On the MS Office forum I found a post that...
3
3772
by: Miro | last post by:
Why Password protect an MDB when someone can google and get a hack? Wondering if anyone else has thought of this and just said "oh well"... I plan to password protect an MDB where I have some system/program variables and data. But looking in google, there are plenty of programs a user can download to hack and crack that password.
0
1680
by: btopenworld | last post by:
Hi I have been using two forms of password protection: A) On working web sites I use an ASP script that is included in every page requiring protection: uses session - works fine B) On quick test sites or temporary stuff I use the Windows Network Authentication provided by my web host. A whole folder is protected at once which is very convenient but it has a problem. If a user types the wrong
16
8385
by: Greg (codepug | last post by:
If one converts that .mdb into an .mde the code is secure but the tables can still be imported. Just for Very Basic protection, I have placed a Password on the database using the "Set Database Password" option. Now it requires that the password be entered each time you start the database. How do I enter the Password using code, so that the database starts up without having to type it in ??? I notice that there is a way in code to set...
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10268
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10031
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.