Re: Perl and Mysql display data problem

"Anthony Tang" <[email protected]>
Newsgroups gmane.comp.db.mysql.perl
Message-ID <001601c69801$5406aa30$0201a8c0@b0bby>
Hello,

I'm pretty experienced with using Perl and MySQL.  Its what I do to build my web applications.  For a authentication scheme, you may want to always check the username and password input.  First do username and password validation before even calling mysql.  For example, if your password supposed to have a minimum of 6 characters, then validate that before you connect to your MySQL database.

Also, you should look into using MD5 for your password column for your user database.

As for your Perl Syntax problem....perhaps chang this part of your coding:

($uid, $password) = $sth->fetchrow_array();
$sth->finish(): #<---CHANGE : to ;                               
if ($input_password eq $password) 
{
         ...
}


----- Original Message ----- 
From: "FoRo" <[email protected]>
To: <[email protected]>
Sent: Saturday, June 24, 2006 6:15 PM
Subject: Perl and Mysql display data problem


> Hello I have several problems. I'm trying to write a perl script that would
> check the username and password from Mysql database and allow users to
> login. I'm new to both systems and i have a lot of oruble with them. Here is
> the perl script that i'm trying to build.
> -----------------------------------------------------------------------------------------------------
> 
> #!/usr/bin/perl -wT
> 
> use strict;
> use CGI;
> use CGI::Carp;
> use DBI;
> use Template;
> 
> 
> # Load the CGI input data.
> my $html = new CGI;
> print $html->header();
> 
> #my $dsn = 'DBI:mysql:ttf:localhost';
> #my $db_user_name = 'web';
> #my $db_password = 'nouser';
> #my ($uid, $password);
> #my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
> 
> 
> my ($sth);
> 
> 
> my ($input_username = "bobob", $input_password = "password") 
> 
> 
> my $sth = $dbh->prepare(qq{
>   select uid, password from logins
>        where username = $input_username
> });
> $sth->execute();
> 
> ($uid, $password) = $sth->fetchrow_array();
> $sth->finish(): 
> if ($input_password eq $password) 
> {
>          ...
> }
> 
> $sth->fetchrow_array()
> 
> my $sth = $dbh->prepare(qq{
>   select fname, lname from users
> });
> $sth->execute();
> while (my ($fname, lname) = 
>  $sth->fetchrow_array())
> {
>     print "$fname, $lname\n";
> }
> $sth->finish();
> 
> 
> my (@matrix) = ();
> while (my @ary = $sth->fetchrow_array())
> {
>   push(@matrix, [@ary]);
> }
> sth->finish();
> 
> 
> $dbh->disconnect();
> 
> -----------------------------------------------------------------------------------------------------
> 
> I keep on getting this errors, i have idea how to fix them. :)
> 
> -----------------------------------------------------------------------------------------------------
> 
> syntax error at ./login.pl line 34, near ")
> 
> 
> my "
> Global symbol "$input_username" requires explicit package name at ./login.pl
> line 34.
> Global symbol "$uid" requires explicit package name at ./login.pl line 40.
> syntax error at ./login.pl line 41, near "):"
> Execution of ./login.pl aborted due to compilation errors.
> 
> -----------------------------------------------------------------------------------------------------
> 
> 
> Any help would be really apreciated.
> 
> Another question i have, how to write the code so it could get for example
> first name and last name. and put them in to a hashed array, so i could
> display only fthe first or last name on the page.
> 
> Once again, thx guys.
> 
> --
> View this message in context: http://www.nabble.com/Perl-and-Mysql-display-data-problem-t1842429.html#a5029478
> Sent from the MySQL - Perl forum at Nabble.com.
> 
> 
> -- 
> MySQL Perl Mailing List
> For list archives: http://lists.mysql.com/perl
> To unsubscribe:    http://lists.mysql.com/[email protected]
> 
> 
> 
> 
> 
> -- 
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.394 / Virus Database: 268.9.3/374 - Release Date: 6/23/2006
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.