Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Password Protection for Web Page.

by augamecock (Novice)
on Dec 14, 2001 at 00:25 UTC ( [id://131749]=perlquestion: print w/replies, xml ) Need Help??

augamecock has asked for the wisdom of the Perl Monks concerning the following question:

I am in the process of creating a webpage with forms that will create HTML documents on my web site. I used CGI.pm to create the page that contains the form and used another script to read and write the contents of the form to a file. Each time the form is submitted it creates a new file. What I'm looking to do is use some sort of password protection for the form page so that my Hard Drive cannot be filled with useless crap. This is the 1st time I have used Perl/CGI. I have the Perl Black Book and have been using it as a reference but am looking for some references on password protection or better yet username and password protection.

My grand plan would be when someone clicked the link to go the the form page and username and password "box" (for lack of a better word) would appear and if those values were correct take them on to the page and if not, deny access.

I am open to suggestions and links for reading. I've done searches on my own but have found no sites that are down to my newbie level yet. Thanks for any help

Replies are listed 'Best First'.
(Ovid) Re: Password Protection for Web Page.
by Ovid (Cardinal) on Dec 14, 2001 at 00:51 UTC

    You seem to have two questions here.

    1. How do I stop my hard drive from filling up when someone posts some data that I save to a file?
    2. How do I password protect a page?

    These are two completely separate issues. It appears that you have a problem (don't want your hard drive filled up) and you are asking how to implement your solution. That's kind of like asking how to peel potatos with a cheese grater. You can do it, but it's not really what you're looking for :)

    Question 1: you can use CGI::Safe to conveniently set a max post size for your uploads (you'll want to read the documentation on how to allow uploads). Then, when you save the file, you'll want to check that the file size plus the current directory size doesn't exceed the max directory size that you have set. From "CGI Programming with Perl", 2nd Edition (by O'Reilly):

    use constant MAX_DIR_SIZE => 100 * 1_048_576; # max of 100 MB use constant UPLOAD_DIR => "/path/to/upload/dir"; # later if ( dir_size( UPLOAD_DIR ) + $ENV{CONTENT_LENGTH} > MAX_DIR_SIZE ) { # don't allow the upload } # later sub dir_size { my $dir = shift; my $dir_size = 0; opendir DIR, $dir or die "Unable to open $dir: $!"; while ( readdir DIR ) { $dir_size += -s "$dir/$_"; } return $dir_size; }

    As for password protecting your pages, there are many ways to do this. You could use .htaccess files (but those don't allow a timeout), but make sure you use them over an encrypted connection. There are other ways, too. I'm sure some other monks can help you here. I need to get back to work :)

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      Thanks Ovid, I'll definetly look into CGI::Safe. I guess I included size of the upload problem as a reason for the password protection. I will only give passwords to the few people I want uploading to my computer.

      I'll also look into the .htaccess files. Didn't even know they existed :)
Re: Password Protection for Web Page.
by archen (Pilgrim) on Dec 14, 2001 at 01:20 UTC
    yeah, I would say .htaccess would be the way to go. Using perl for security in that situation would probably be sloppy at best. As for preventing your hard drive from filling, perhaps you can make a log of people who submit the form, and prevent people from submitting too many times. You could also have the script check the total number of files submitted and just crap out once that number gets too high (or maybe automatically compress/archive them)

    I also used the Black Book for my first/main Perl reference. Informative, but HORRIBLY organized
Re: Password Protection for Web Page.
by scottstef (Curate) on Dec 14, 2001 at 18:43 UTC
    One of the options for filling up your hard drive could also be to create a seperate partition for the machine. This is not that hard to do, and then have that partition be for your data. If it fills up at worst your app won't work, but the machine still will.
    HTH

    "The social dynamics of the net are a direct consequence of the fact that nobody has yet developed a Remote Strangulation Protocol." -- Larry Wall

Re: Password Protection for Web Page.
by atcroft (Abbot) on Dec 14, 2001 at 15:19 UTC

    I humbly submit the following idea for your consideration:

    1. Click on link to go to form, and they go to a page asking for username/password (or other authenticating tokens) (and advises that the site uses cookes you'll see why in a moment.
    2. Submitting username/password form checks against a database (be it full-blown database, or text file, or whatever).
    3. Set a cookie in their browser if successful, then refer/redirect them to the form page.
    4. If cookie is set, display form; otherwise, display an "access unavailable" message.
    5. Optionally, update the/another cookie with the number of times they have submitted, which can be checked against the maximum number of times you wish to allow them to submit.

    I am sure there are more experienced monks here who may offer better/easier solutions. Good luck with your project.

Re: Password Protection for Web Page.
by dws (Chancellor) on Mar 12, 2002 at 22:03 UTC
    I'm looking to do is use some sort of password protection for the form page so that my Hard Drive cannot be filled with useless crap.

    I run a password-protected Wiki clone under Apache, using something like the following .htaccess

    Options Includes ExecCGI AuthType Basic AuthName "Conference Forum" AuthUserFile /usr/home/dws/.htpasswd ErrorDocument 401 /aye/noauth.html <Files ~ "\.cgi$"> <Limit GET> require valid-user </Limit> </Files>
    Because the posting page is itself produced by a .CGI, and contains some magic stuff in hidden fields, I don't need to limit POST requests. Raw data pages are kept in a subdirectory. The .htaccess in that subdirectory reads
    Order deny,allow Deny from all
Re: Password Protection for Web Page.
by pmas (Hermit) on Mar 12, 2002 at 21:40 UTC
    It might be too late for this, but maybe not. Maybe you are ready to look at it with fresh eyes:

    Look at http://twiki.org. It might be what you are looking for. And for simplest wiki (but without protection), look at www.seedwiki.com, where you can start your own wiki for free.

    pmas
    To make errors is human. But to make million errors per second, you need a computer.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://131749]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-19 10:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found