Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Perl/CGI login

by swkronenfeld (Hermit)
on Dec 02, 2005 at 23:01 UTC ( #513746=note: print w/replies, xml ) Need Help??

in reply to Perl/CGI login

There's modules that can do work for you, but if you're wanting to do something fairly simple and learn in the process, you can roll a pretty simple script. Here's a generic (and simplistic) skeleton to give you an idea.

use CGI; my $cgi = new CGI; my $user = $cgi->param("username"); my $pass = $cgi->param("password"); my $valid = 0; # Assuming usernames/passwords in a delimited text file open(IN, "passwordFile") or die(...); while(<IN>) { if( /^$user\:$pass$/ ) { $valid = 1; last; } } close(IN) if(!$valid) { print "Sorry, you may not access this page."; exit; } #set authentication #set a cookie here using javascript or #add hidden fields with login info print "<input type='hidden' name='pass' value='...'>"; print "<input type='hidden' name='user' value='...'>"; Store usernames/passwords in a file as follows: johndoe:myPassw0rd user2:pass2 user3:pass3 etc

You have to decide how you wish to keep users authenticated. There a number of approaches you can take. Since it sounds like you want something simple, the easiest ways may be to either set a cookie for the user or to pass around a hidden <input> field. Neither of those is very secure, but neither is a plain text password file. How worried are you about security, do you need more than that?

Replies are listed 'Best First'.
Re^2: Perl/CGI login
by muclc7 (Initiate) on Dec 03, 2005 at 00:00 UTC
    Your skeleton is most helpful in giving me an idea of the process when using Perl/CGI (Perl is the first language I am learning). The login does not have to be too secure as it is just for my family members to view my online photo album (and an excuse to learn/use Perl). I have not used cookies or hidden fields yet, but I have a Perl book that references them. Which would you recommend I try first (i.e. which is simple to put together). Thank you.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://513746]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2022-12-09 23:39 GMT
Find Nodes?
    Voting Booth?

    No recent polls found