473,473 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Password protection and prevent download

Hello all
I'm completely new to php but a complete newbie when it comes to unix.
So please don't laugh about my problem.

I have programmed a nice password check with php, javascript and a
database and it works. But as I have removed the access control with
..htaccess on the server I recognized that everybody can now directly
download all documents without a password, as long as they know the
filename and location.

I assume that for any unix hacker it should not be a problem to find
all filenames somehow.
Is this true ? Have I opened a security hole on the server?
If yes, how can I prevent it. And how can I protect some directories
with sensitive data and only show it when somebody has properly
entered his personal passsword.
I mean is it possible to still use the .htaccess on some directories
and grant access to this directory for those users that correctly
identified itself, without having to enter another password ?

thanks
greets
Juerg
** Posted from http://www.teranews.com **
Sep 5 '08 #1
1 2198
Juerg Beck wrote:
I have programmed a nice password check with php, javascript and a
database and it works. But as I have removed the access control with
.htaccess on the server I recognized that everybody can now directly
download all documents without a password, as long as they know the
filename and location.
Suppose your files are in http://www.example.org/files/. If your server
is configured to show a directory index, it will show a list of files
when someone requests http://www.example.org/files/. This is not what you
want, so you could turn of directory index for that directory. That will
make it very hard for any visitor to get a list of files.

Another way to get a list of files is when someone has access to your
server. For example, if you host your site on a shared host, other people
using the same host may be able to get a list of files.

Finally, someone may just guess the filename or pass the URL on to
friends and family.

What you really want is that people can only the files through your
script, and can not pass the URL around.

To do this, you put your files outside of your document so that they are
no longer accessible through http://www.example.org/files/ or any other
URL. To access the file, you make a PHP script which first checks the
password and then serves the file. This makes downloading the file
without the password impossible.

It goes something like this:
<?php
$pass = $_POST['password'];
if ($pass == 'supersecret') {
$file = 'protectedfile.mp3';
// Set some headers to indicate that the user is downloading
// a file
header('Content-type: binary/octet-stream');
header('Content-disposition: attachment; filename='.$file);
header('Content-length: '.filesize($file));

// Pass the file to the visitor.
readfile($file);
} else {
echo 'Wrong password.';
}
?>
Sep 5 '08 #2

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

Similar topics

3
by: Wm | last post by:
Something just occurred to me... <yeah, I know, it scared me too> I just password-protected a website by including a password authentication script in each page of a private section. The script...
3
by: Yang | last post by:
Anyone know a way to download an image using php which has a hotlink protection ?
9
by: Howard | last post by:
I am currently looking at the various packages that are available for software protection. I have a particular question that I'd welcome your feedback on. Background info: I work for a company...
3
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...
22
by: teejayem | last post by:
Hi, I am new to programming with databases and was wanting some help. Is there any way to password protect an access database and access sent sql commands to it via vb.net code? Any help...
30
by: diane | last post by:
I've got an application running with table-based security: i capture the user's windows login with fOsusername, then have them enter a password checked against their username/login in my own table....
1
by: anco85 | last post by:
Hi. Im a total access and VB noob and require your much appreciated help. I have a table that list all the vehicles in our company. I created a form to view this information much easier with a...
16
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...
1
by: denniswong288 | last post by:
Hi, My website has PDF documents that's available for registered users to view online (through my site) only. Currently, I can't find any solutions to prevent users from downloading/"save-as"...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
1
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.