Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Login Script

by scorpio17 (Abbot)
on Aug 28, 2012 at 21:03 UTC ( #990334=note: print w/replies, xml ) Need Help??

in reply to Login Script

The code where you retrieve your form parameters should like something like this:

my $user_name = $cgi_object->param('user_name'} || ''; my $passwd = $cgi_object->param('passwd') || ''; unless ($user_name && $passwd) { # handle cgi param error }

The database query needs to use a placeholder, and check for errors - something like this:

eval { $sth = $dbh->prepare("select pass from users where user=?"); $sth->execute($user_name); }; if ($@) { # handle database error }

Since HTML is stateless, you need to use something like CGI::Session to remember that a particular user is logged in.

Using a framework will make your life much easier. Here's a link to a simple login tutorial I wrote:
RFC: Proposed tutorial - simple login script using CGI::Application

That should help get you started.

Replies are listed 'Best First'.
Re^2: Login Script
by ironside (Acolyte) on Aug 30, 2012 at 08:44 UTC
    That's a big help. Thank you.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990334]
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: (8)
As of 2016-10-28 20:39 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (387 votes). Check out past polls.