Click to See Complete Forum and Search --> : Password Protect a Directory


netvizion
02-10-2003, 10:41 AM
Hello. Can someone give me some help (or point me to some help) on password protecting a directory with asp? I know how to protect single asp pages, but I also have some .pdf and .doc files that need to be protected, so I need to just protect the whole directory I guess. I asked the hosting company to set it up, and they said they could only do one username/password combination, and if I want more than that I need to do it in asp myself. (I have about 20 username/passwords).

Thank you!

Ribeyed
02-11-2003, 06:15 AM
Hi,
I am not sure how to solve your problem but maybe this following will help:

The File object represents a file and provides properties, which represent the various properties of the actual file. It also provides methods, which let you copy, move and delete files.

To obtain a File object and examine its properties, use the following steps:
1. Create a FileSystemObject variable by declaring it as follows:

Set FSYS = CreateObject(“Scripting.FileSystemObject”)

2. Use the FSYS variable to obtain an object that represents a specific file:

Set file = FSYS.GetFile(filename)

Where filename is the desired file’s path name (c:\Intput\wwwroot\images.image.bmp, for example).

3. Then access the file’s properties through the file object variable:

FName = file.Name
FDate = file.DateCreated
FSize = file.Size

You use the Attributes property to read or set a file’s attributes, such as read-only, archive, hidden, and so on). The attributes of a file are numeric values and a file can have multiple attributes. In this case, the file’s attribute is the numeric sum of the values of the individual attributes.

Syntax

fileAttibutes = thisFile.Attributes

The attribute variable can have any of the following values:

Hidden file = 2
System file = 4
Volume = 8
Directory = 16
Archive = 32
Alias = 64
Compressed = 2048

To find out whether a file is ready-only, use this statement:

IF thisFile.Attributes and 1 Then
‘The files is Ready-only
End If

To delete the file, you must first change the ready-only attribute of the file with a statement like the following one:

If thisFile.Attributes And 1 Then
thisFile.Attributes = thisFile.Attributes + 1
End If

Normally, when we set a file’s attributes, we don’t reset the existing ones. For example, you many choose to add the hidden attribute from a file that has its ready-only attribute set. To turn on the hidden attribute without affecting the other ones, use a statement such as:

thisFile.Attributes = thisFile.Attributes + 2

or you can use this:

thisFile.Attributes = thisFile.Attributes Or 2

To remove a specific attribute, first find out wether this attribute is already set, and then subtract its value for the Attributes property’s value. To remove the Hidden attribute, use a structure like the following one:

If thisFile.Attributes And 2 Then
thisFile.Attributes = thisFile.Attributes – 2
End If

Im sure you can access the Folder attributes using the above method but using this line:

Set FSYS = CreateObject(“Scripting.FileSystemObject”)
set ThisFolder = FSYS.GetFolder(FolderName)

Hope this helps.

netvizion
02-11-2003, 11:08 AM
That's great information, but I don't think it really does what I'm looking for. I may end up embedding the pdf files in asp pages and just converting the .doc files to asp. That way I can check for authorized users within the pages. I can't believe there's not some other way of doing this though.

I'm trying to convert a site that a client had on another server, and they were using .htaccess to protect the directory, but I understand this doesn't work with windows servers. :(

Thanks anyway.